我是使用 Gitlab 运行程序的新手,我正在尝试编写一个管道来更改文件,然后提交该文件并将其推送到 main。在尝试执行此操作并尝试其他解决方案时,我遇到了许多不同的错误。如果有人提出对他们有用的解决方案的建议,我们将不胜感激。
这是我的 gitlab-ci.yml 文件中的内容:
`stages:
- build
write_logfile:
stage: build
script:
- echo "This is a log message" > logfile.txt
- git config user.email "[email protected]"
- git config user.name "access-token-name"
- git remote add gitlab_origin
- https://oauth2:[email protected]/path-to-project.git
- git add .
- git commit -m "push back from pipeline"
- git push gitlab_origin HEAD:main -o ci.skip
rules:
- changes:
- 'Source/*'`
我从此页面找到了这个,但我不断收到以下错误: 远程:HTTP 基本:访问被拒绝。提供的密码或令牌不正确,或者您的帐户启用了 2FA,并且您必须使用个人访问令牌而不是密码。
我的帐户没有 2FA,所以我不确定我做错了什么。
我改变了一些东西来解决这个问题:
将
GIT_STRATEGY
变量设置为 Clone
检查分支以避免分离头,并正确使用项目访问令牌(见下文)
git checkout $CI_COMMIT_REF_NAME
git config user.name "CI Pipeline"
git config user.email "[email protected]"
echo "This is a log message" >> logfile.txt
git add .
git commit -m "updating logfile [skip ci]"
# Here we set the URL of the remote we want to push to
git remote set-url --push origin "https://token-name:[email protected]/${CI_PROJECT_PATH}.git"
git push --set-upstream origin $CI_COMMIT_REF_NAME