Gitab CI: 有关对目录/路径进行更改的规则

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

Gitab CI : rules with changes to a dir/path

问题

我正在尝试在我的CI中添加这个逻辑:

  • 不要在 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-4.html
匿名

发表评论

匿名网友

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

确定