如何创建评估为AND而不是OR的Gitlab CI规则 [英] How to create Gitlab CI rules that are evaluated as AND instead of OR
问题描述
如果将变量$ CI_COMMIT_TAG设置为 OR (如果./versions.txt文件已更改),则以下gitlab ci作业将运行.
The following gitlab ci job will run if the variable $CI_COMMIT_TAG is set OR if the ./versions.txt file has changed.
some-job:
script:
- echo "Do some fancy stuff.";
rules:
- if: $CI_COMMIT_TAG
when: always
- changes:
- ./versions.txt
但是,我需要的是在$ CI_COMMIT_TAG设置为 AND ../versions.txt更改时运行此作业.如果只有其中一项评估为真,我不希望这项工作继续进行.这是仅/更改"功能中的行为,但是唯一(且除外)功能的功能较弱且已弃用.
However, what I need is for this job to run when $CI_COMMIT_TAG is set AND ./versions.txt is changed. I don't want the job to run if only one of these evaluates to true. This was the behaviour in only/changes feature, but the only (and except)-feature is less powerful and deprecated.
我现在想用gitlab ci做些什么吗?
Is what I want currently possible with gitlab ci?
推荐答案
来自在以下示例中:
如果Dockerfile或docker/scripts/中的任何文件已更改 AND $ VAR =="string value",我们将手动运行作业.否则,该作业将不包括在管道中.
We run the job manually if Dockerfile or any file in docker/scripts/ has changed AND $VAR == "string value". Otherwise, the job will not be included in the pipeline.
docker build:
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- if: '$VAR == "string value"'
changes: # Will include the job and set to when:manual if any of the follow paths match a modified file.
- Dockerfile
- docker/scripts/*
when: manual
您的代码将如下所示.
some-job:
script:
- echo "Do some fancy stuff.";
rules:
- if: $CI_COMMIT_TAG
changes:
- versions.txt
when: manual
这篇关于如何创建评估为AND而不是OR的Gitlab CI规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!