You won't be able to get your desired result using the only
syntax due to the way it's evaluated. The example you have above is a simple/shorthand way of using the refs
keyword, so it is the same thing as
only:
refs:
- /^v(d+).(d+).(d+)$/ #tag
- web
For this alone, the job will be added to the pipeline if any of the refs matches. When combined with the other keywords (like variables
or kubernetes
), the keywords are combined using AND's. So with this example, one of the refs must match, AND the variable must match. There's no way to make it an OR.
only:
refs:
- /^v(d+).(d+).(d+)$/ #tag
- web
variables:
- $CI_COMMIT_MESSAGE =~ /^my message/
You should be able to get your desired result using the newer rules
syntax though. If you have multiple if
statements, they are OR'ed together, not AND'ed. An example of how if's are evaluated are in the docs here: https://docs.gitlab.com/ee/ci/yaml/#rules-clauses. In a single if statement, you can combine conditions using ||
for OR and &&
for AND. You can see examples of that here: https://docs.gitlab.com/ee/ci/yaml/#rulesif
So for this use case, I'd try either
rules:
- if: '$CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_MESSAGE =~ /^my message/i || $CI_COMMIT_REF_NAME =~ /^v(d+).(d+).(d+)$/'
when: always
You're not required to add the when clause to your if statements, and if you don't it will use the when
you put on the job, or use the default on-success
.
Also, all the pre-defined variables you can use are listed here: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…