gpt4 book ai didi

continuous-integration - GitLab CI 运行 Job only refs AND changes

转载 作者:行者123 更新时间:2023-12-04 15:32:58 26 4
gpt4 key购买 nike

我只想为 merge_requests refs 和指定文件的更改运行作业,according to official doc我在 .gitlab-ci.yml 中创建了这个作业:

merge-request-test:
<<: *some_anchor
only:
refs:
- merge_requests
changes:
- "*.py"
- "**/*.py"
- postman/some-file.json

但即使我更改任何其他文件,这项工作也会开始。

我知道 GitLab CI 对 refschanges 部分应用 OR 规则:

In the example below, the test job will not be created when any of the following are true:

The pipeline runs for the master. There are changes to the README.md file in the root directory of the repo.

test:   
script: npm run test
except:
refs:
- master
changes:
- "README.md"

我只想在 MR 更改指定文件时启动此作业。我怎样才能实现这种行为?

如果删除 refs 部分,它仅在文件更改时有效,但官方文档不建议这样做,因为我想在管道中使用它:

If using only:changes with only allow merge requests to be merged if the pipeline succeeds, undesired behavior could result if you do not also use only:merge_requests.

最佳答案

现在我有了这个可行的解决方案:

merge-request-deploy:
<<: *deploy-app
rules:
- if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
changes:
- "*.py"
- "**/*.py"
- postman/some-file.json
when: always
  • if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~/^feature/&& $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"' - 给我 MR 分支
  • changes - 给我更改的文件

规则的部分适用于 AND 规则。

关于continuous-integration - GitLab CI 运行 Job only refs AND changes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60814439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com