如何让 Gitlab 运行器在成功构建时将代码合并到分支中 [英] How can I make Gitlab runner merge code into a branch on a successful build
本文介绍了如何让 Gitlab 运行器在成功构建时将代码合并到分支中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗯,标题是不言自明的.
Well the title is pretty much self-explanatory.
总之,如果构建成功,我希望将一个分支(即 dev)合并到另一个分支(即生产).
In summary, I want a branch (i.e. dev) to be merged to another branch (i.e. production) IF the build is successful.
推荐答案
我尝试了@jakub-kania 解决方案,但我总是得到 id_rsa invalid format
.我认为 gitlab 秘密变量以某种方式被搞砸了.
I tried @jakub-kania solution but I was always getting id_rsa invalid format
. I think that gitlab secret variables are screwed somehow.
我通过直接将部署密钥传递给 ssh-add 而不创建 ssh 密钥来使其工作.这是可行的解决方案:
I made it working by directly passing the deployment key into ssh-add without creating ssh keys. Here is working solution:
merge to master:
stage: deploy
image: alpine
only:
- dev-branch
before_script:
- apk add --update git openssh-client
- mkdir ~/.ssh
- ssh-keyscan -p 2222 <gitlab.domain.com> > ~/.ssh/known_hosts
- eval `ssh-agent -s`
- ssh-add <(echo "$GITLAB_DEPLOY_KEY")
- ssh -T git@<gitlab.domain.com> -p 2222
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_ID"
- git remote set-url origin ssh://git@<gitlab.domain.com>:2222/path/to/repo.git
script:
- git checkout master
- git reset --hard origin/master
- git merge $CI_BUILD_REF
- git push origin master
这篇关于如何让 Gitlab 运行器在成功构建时将代码合并到分支中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文