简体   繁体   English

Gitlab CI 根据合并请求自动运行管道

[英]Gitlab CI automatical run pipeline on merge request

I have below pipeline.我有以下管道。 After creating merge request, created Detached merge request pipeline with failed status (app1 - no stages/jobs).创建合并请求后,创建了状态为失败分离合并请求管道(app1 - 无阶段/作业)。 In scope of below pipeline need to run pipeline when merge request is created and after merging changes main.在下面管道的 scope 中,需要在创建合并请求时运行管道,并且在合并更改后主要。 Flow described in here Gitlab CI Child pipeline Below pipeline does not work.此处描述的流程Gitlab CI 子管道下面的管道不起作用。


workflow:
    rules:
        - if: '$CI_PIPELINE_SOURCE == "schedule"'
        - if: '$CI_PIPELINE_SOURCE == "web"'
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
        - if: '$CI_PIPELINE_SOURCE == "push"'

stages:
    - child-pipelines

app1:
    stage: child-pipelines
    variables:
        COMPONENT NAME: 'app1'
    trigger:
        include:
        - local: .ci/.gitlab-ci.yml
        strategy: depend
    rules:

        - if: $CI_PIPELINE_SOURCE == "merge_request_event"
          changes:
            - test1/**/*
          variables:
            DEPLOY_RELEASE: '11111'

        - if : '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
          changes:
            - test1/**/*
          variables:
            DEPLOY_RELEASE: '222222'
app2:
    stage: child-pipelines
    variables:
        COMPONENT NAME: 'app1'
    trigger:
        include:
        - local: .ci/.gitlab-ci.yml
        strategy: depend
    rules:

        - if: $CI_PIPELINE_SOURCE == "merge_request_event"
          changes:
            - test2/**/*
          variables:
            DEPLOY_RELEASE: '11111'

        - if : '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"'
          changes:
            - test2/**/*
          variables:
            DEPLOY_RELEASE: '222222'


If you want to run a pipeline when merge request was created and after merge to main branch, take a look this example:如果您想在创建合并请求并合并到主分支后运行管道,请查看以下示例:

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
    
job1:
  script:
    - echo "This job runs in merge request and also after merge to main branch"

According to Gitlab documentation .根据Gitlab 文档

If you want to run a rule for the entire pipeline:如果要为整个管道运行规则:

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
  
job1:
  script:
    - echo "This job runs in merge request pipelines"
    
job2:
  script:
    - echo "This job also runs in merge request pipelines"

If you want to run a rule in certain job:如果您想在某个作业中运行规则:

job1:
  script:
    - echo "This job runs in merge request pipelines"
  only:
    - merge_requests

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

相关问题 在 gitlab ci MR 管道上运行所有作业,即使有些没有 merge_request_event 规则,但不要同时运行 MR 和分支管道 - Run all jobs on a gitlab ci MR pipeline, even if some don't have a merge_request_event rule, but do not run both MR and branch pipelines 使用 Bash 和 cURL 通过 CI/CD 管道进入时生成 GitLab 合并请求 - Generate GitLab Merge Request when a push comes in via CI/CD Pipeline using Bash and cURL 如何让 Gitlab CI 管道始终运行某些作业而仅在合并请求上运行其他作业? - How to have a Gitlab CI Pipeline run some jobs always and other jobs only on merge-requests? Gitlab-ci - 管道运行失败 - Gitlab-ci - Pipeline Fails to run GitLab CI/CD 管道 - 在 GitLab Runner 上交互式运行 Linux 命令 - GitLab CI/CD Pipeline - Run Linux commands interactively on GitLab Runner 接受合并请求后禁用 gitlab 管道 - disable gitlab pipeline after merge request is accepted Gitlab CI管道解压问题 - Unzip problems in Gitlab CI pipeline 如何在自动运行的情况下手动运行 GitLab CI 管道? - How to enable to run a GitLab CI pipeline manually outside of cases where they are run automatically? 尝试更新 my.gitlab-ci.yml 文件以运行 SAST 并且管道失败(无法提取图像) - Trying to update my .gitlab-ci.yml file to run SAST and the pipeline fails (Failed to pull image) 测试没有在我的 gitlab-ci 管道中运行 - Tests are not running in my gitlab-ci pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM