[英]In Gitlab CI/CD how to checkout another branch during the pipeline
I would like to checkout to dev
branch in a merge request pipeline that is opened for merging to dev
with some other branch.我想签出合并请求管道中的dev
分支,该管道已打开以与其他分支合并到dev
。 I am going to check somethings in this job and then continue with some other jobs depending on the success of this one.我将检查这项工作中的某些内容,然后根据这项工作的成功继续进行其他一些工作。 Is it possible to do such thing or do I always have to work with the branch the pipeline triggered at?是否可以做这样的事情,或者我是否总是必须使用管道触发的分支?
I add the related part of the gitlab configuration我添加了gitlab配置的相关部分
variables:
GIT_STRATEGY: clone
checksomething:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
environment:
name: development
before_script:
- git checkout dev
script:
- !reference [.check-something-on-dev]
But I have this error:但我有这个错误:
$ git checkout dev
error: pathspec 'dev' did not match any file(s) known to git```
Actually it was this easy:其实就是这么简单:
before_script:
- git fetch origin dev
- git checkout dev
Try first a git branch -avv
to see what branches are available through the original clone/checkout done the GitLab-CI job.首先尝试git branch -avv
以查看哪些分支可通过原始克隆/签出完成 GitLab-CI 作业。
Depending on the refspec used, the cloned repository might not reference any origin/dev
branch, preventing the guess mode of git checkout
(or, for that matter, of git switch
, the more modern alternative to checkout
) to work.根据使用的refspec ,克隆的存储库可能不引用任何origin/dev
分支,从而阻止git checkout
(或者,就此而言, git switch
, checkout
的更现代替代方案)的猜测模式工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.