Reputation: 514
I saw this code on one of the pipelines of my company.
rules:
- if: 'SOME-CONDITION'
when: manual
- when: never
variables:
...
According to gitlab ci documentation, the when:never
field should be used with a condition, to basically tell the pipeline to not add the job if that condition is satisfied. I don't understand its use by itself in the end of the rules. What does it add and how the pipeline will behave without it ?
Upvotes: 5
Views: 24399
Reputation: 31
I think that at the end of the rules block the line when: never
tells that the pipeline should not be run in any other cases.
Because by default it runs after each commit in any created MR.
Upvotes: 3
Reputation: 1374
Like others have said, the - when:
is how you do an 'else' condition. However, in this case it is redundant because - when: never
is the default 'else' when rules are used.
As far as why this code is there... This may just be a personal preference or coding standard. Sometimes it's nice to make this explicit for clarity, even if redundant.
Upvotes: 0
Reputation: 1
Imagine rules as a switch with different cases. Satisfying the first condition encountered means that further conditions are not checked.
rules:
- if: 'SOME-CONDITION'
when: manual
- if: 'SOME-CONDITION-2'
when: manual
- when: never
So if SOME-CONDITION is met, job is manual and compilation stops on this condition. If SOME-CONDITION-2 is met, job is manual and compilation stops on this condition. If !SOME-CONDITION and !SOME-CONDITION-2, job will never run.
if SOME-CONDITION || SOME-CONDITION-2 then manual
fi
never
Upvotes: 0
Reputation: 104
The last when: never
is not needed.
Even without that line, the job will run only if SOME-CONDITION
is satisfied.
Upvotes: 2