我想将手动作业添加到我的拉取请求中,以在运行手动作业时标记我的源分支。该标签将触发我的 bitrise 配置的构建。
然而,当我尝试推送我的标签时,我遇到了这个问题。
注意:我尝试将标签推送到的分支不受保护。
$ git checkout $CI_COMMIT_REF_NAME
Switched to a new branch 'feature/gitlab-ci'
Branch feature/gitlab-ci set up to track remote branch feature/gitlab-ci from origin.
$ git tag build-bitrise
$ git push --tags
remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:[MASKED]@gitlab.com/my-app/my-app.git/': The requested URL returned error: 403
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
我的工作是这样做的:
- git remote show origin
- git fetch
- git checkout $CI_COMMIT_REF_NAME
- git tag build-bitrise
- git push --tags
在我的“before_scripts”步骤中,我这样做:
before_script:
# Install ssh-agent through openssh-client if not present
- 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
# Add the private key to this user
- eval $(ssh-agent -s) && ssh-add <(echo "$SSH_PRIVATE_KEY") && mkdir -p ~/.ssh
# Config git to avoid first usage questions. Set the identity
- git config --global user.email "[email protected] /cdn-cgi/l/email-protection" && git config --global user.name "Louis Lecocq"
其中 SSH_PRIVATE_KEY 是一个变量,它是我在 ENV 中的 GITLAB 配置文件的复制/粘贴。
感谢您的阅读和您的时间
我认为您当前的方法不起作用,因为它仍在使用https
而不是ssh
为了做git tag
根据错误消息,所以没有使用您的SSH_PRIVATE_KEY
:
fatal: unable to access 'https://gitlab-ci-token:[MASKED]@gitlab.com/my-app/my-app.git/': The requested URL returned error: 403
您也许可以通过更新来使其工作(未经测试)git remote
在执行此操作之前手动git push --tags
,即:
git remote set-url origin [email protected] /cdn-cgi/l/email-protection:my-group/my-app/my-app
使用的替代方案SSH_PRIVATE_KEY
是使用 API 密钥。您可以创建具有 API 访问权限的个人访问令牌https://gitlab.com/-/profile/personal_access_tokens https://gitlab.com/-/profile/personal_access_tokens,然后将密钥添加到CI/CD Variables
as API_KEY
例如。
然后在你的脚本部分,你可以有类似的东西:
script:
- # something to do before pushing the tag
# sometimes the remote might already exist (if using the same runner), let's just remove it and don't fail
- git remote remove https-origin || true
# add new https-origin remote which uses the API_KEY
- git remote add https-origin https://gitlab-ci-token:${API_KEY}@gitlab.com/my-group/my-app.git
# tag your build
- git tag build-bitrise
# push only the build-bitrise tag using the https-origin ref, and skip CI build
- git push https-origin -o ci.skip refs/tags/build-bitrise
注意,建议对 API_KEY 使用机器人帐户,否则 API_KEY 将具有与您的用户相同的权限,并且可能会被能够看到 CI/CD 变量等中的密钥的其他维护者泄露。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)