简体   繁体   English

Gitlab-ci.yml 配置

[英]Gitlab-ci.yml Configuration

I want to run job only when there is merge request to specific branch.我只想在对特定分支有合并请求时运行作业。 I configure .gitlab-ci.yml file as follow我配置 .gitlab-ci.yml 文件如下

stages:
  - test
  - deploy

test:
  stage: test
  only: 
  - develop
  - merge_requests

deploy:
  stage: deploy
  only: 
  - master
  - merge_requests

This will even run job deploy when merge request is for develop branch.当合并请求是针对开发分支时,这甚至会运行作业部署。 How can I configure gitlab-ci.yml file so that when there is merge request for develop, test job will run and when there is merge request for master, deploy job will run.如何配置 gitlab-ci.yml 文件,以便在有针对开发的合并请求时,测试作业将运行,当有对主服务器的合并请求时,将运行部署作业。

You can use rules for this case, by making gitlab-ci execute the job when there is a merge request targeting a specific branch like below您可以在这种情况下使用rules ,当存在针对特定分支的合并请求时,通过使 gitlab-ci 执行作业,如下所示

stages:
  - test
  - deploy

test:
  stage: test
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
      when: always

deploy:
  stage: deploy
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
      when: always

For more information check out the docs有关更多信息,请查看文档

try changing merge_request to merge_requests.尝试将merge_request 更改为merge_requests。 The docs suggest using merge_requests, so I feel a typo is what is causing this issue for you.文档建议使用merge_requests,所以我觉得打字错误是导致您出现此问题的原因。

gitlab ci docs gitlab ci 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM