作者:value'); DROP TABLE table; | 来源:互联网 | 2023-02-12 15:46
那么标题几乎是不言自明的.
总之,如果构建成功,我希望将分支(即dev)合并到另一个分支(即生产).
如果你想知道为什么,请看看这个问题:https:
//stackoverflow.com/questions/42109335/gitlab-runner-starts-merge-automate-merge?noredirect=1#comment71394445_42109335
1> karser..:
我尝试了@ jakub-kania解决方案,但我总是得到id_rsa invalid format
.我认为gitlab秘密变量以某种方式被搞砸了.
我通过直接将部署密钥传递给ssh-add而不创建ssh密钥来实现它.这是工作解决方案:
merge to master:
stage: deploy
image: alpine
only:
- dev-branch
before_script:
- apk add --update git openssh-client
- mkdir ~/.ssh
- ssh-keyscan -p 2222 > ~/.ssh/known_hosts
- eval `ssh-agent -s`
- ssh-add <(echo "$GITLAB_DEPLOY_KEY")
- ssh -T git@ -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@:2222/path/to/repo.git
script:
- git checkout master
- git reset --hard origin/master
- git merge $CI_BUILD_REF
- git push origin master
2> Jakub Kania..:
最简单的解决方案是创建一个Merge Request并单击"Pipeline Succeeds时合并"按钮,这将在构建后合并分支.这是我推荐的那个.
以下是我不推荐用于自动合并的工作解决方案.它要求您创建具有写访问权限的部署密钥,并将私钥保存为项目变量GITLAB_DEPLOY KEY
,也可以ssh-keyscan
在服务器上执行并将其保存到GITLAB_PUBLIC_KEY
变量.
mergetomaster:
stage: deploy
image: alpine
only:
- dev
script:
- apk add --update git openssh-client
- mkdir ~/.ssh
- echo $GITLAB_DEPLOY_KEY > ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
- echo $GITLAB_PUBLIC_KEY > ~/.ssh/known_hosts
// Steal the identity of person that triggered the build
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_ID"
- git remote set-url origin
- git checkout master
- git reset --hard origin/master
- git merge $CI_BUILD_REF
- git push origin master