GitLab CI:对目录/路径的更改规则

huangapple go评论60阅读模式
英文:

Gitab CI : rules with changes to a dir/path

问题

  • 不要添加作业到流水线,当merge_request_events触发或者合并请求目标分支受保护且对e2e目录中的任何文件进行更改时。
  • 添加作业当我要合并到的分支是以下之一:devtestdemo
  • 在其他情况下不要添加作业到流水线。

这是我的规则:

.ci-rules:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"'
      changes: 
        - "e2e/**/*"
      when: never
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      when: always
    - when: never

build:
  rules:
    - !reference [.ci-rules, rules]
  stage: build
  script:
    - echo "do something"
  allow_failure: false

问题:
当我更改e2e目录中的文件时,作业仍然被添加到流水线中。

英文:

I'm trying to add this logic in my CI :

  • don't add job to pipeline on merge_request_events or when merge request target branch is protected and when changes are made to any file in the e2e directory
  • add job when the branch to which I'm merging to is one of the following dev, test or demo
  • don't add job to pipeline in any other case.

Here are my rules

.ci-rules:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"'
      changes: 
        - "e2e/**/*"
      when: never
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      when: always
    - when: never


build:
  rules:
    - !reference [.ci-rules, rules]
  stage: build
  script:
    - echo "do something"
  allow_failure: false

Issue:
When I make changes to files in e2e directory only the job is still added to the pipeline.

I'd appreciate any help

答案1

得分: 0

这是我使用以下代码解决的:

.ci-rules:
  rules:
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      changes:
        - "e2e/**/*"
      when: never
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      when: always
    - when: never
英文:

I solved this with the following

.ci-rules:
  rules:
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      changes: 
        - "e2e/**/*"
      when: never
    - if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
      when: always
    - when: never

huangapple
  • 本文由 发表于 2023年3月21日 01:48:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793635-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定