[英]Use pushed branch name in gitlab-ci script
I have this gitlab-ci script that run on branch with the prefix staging-
using regex and command in the script that checkout to the pushed branch.我有这个 gitlab-ci 脚本,它在带有前缀staging-
的分支上运行——使用脚本中的正则表达式和命令来签出到推送的分支。 How can I use the pushed branch name in the script?如何在脚本中使用推送的分支名称? I tried using the same regex and the job failed.我尝试使用相同的正则表达式,但工作失败了。
deploy:
tags:
- server
only:
- /^staging-.*$/
script:
- cd /var/www/project
- sudo git reset --hard HEAD
- sudo git clean -fd
- sudo git checkout /^staging-.*$/
- sudo git pull origin /^staging-.*$/
After a bit reading in Gitlab docs, I found that using predefined variables works best.在阅读 Gitlab 文档后,我发现使用预定义变量效果最好。
Source: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html资料来源: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
deploy:
tags:
- server
only:
- /^staging-.*$/
script:
- cd /var/www/project
- sudo git reset --hard HEAD
- sudo git clean -fd
- sudo git checkout ${CI_COMMIT_BRANCH}
- sudo git pull origin ${CI_COMMIT_BRANCH}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.