Using rules to control when a job runs breaks the CI pipeline
Summary
Using rules in a job to control when the job runs causes the pipeline block despite the obvious behavior being that the pipeline continues running. Using when: manual works as documented which is that the pipeline will skip the job and continue running, but if there is a rule that contains when: manual it will block the pipeline which is counterintuitive.
Steps to reproduce
Try this CI configuration which uses when: manual in the test job and runs as expected: the test job is skipped and the deploy stage starts running.
stages:
- build
- test
- deploy
build:
stage: build
script: exit 0
test:
stage: test
when: manual
script: exit 0
deploy:
stage: deploy
script: exit 0
On the other hand the following configuration does not work as expected despite being the same thing. In this case the rules cause the pipeline to block because it falls into when: manual. This is effectively the same thing as the previous configuration, but the result is completely different.
stages:
- build
- test
- deploy
build:
stage: build
script: exit 0
test:
stage: test
rules:
- if: $CI_COMMIT_BRANCH == ""
when: always
- when: manual
script: exit 0
deploy:
stage: deploy
script: exit 0
What is the current bug behavior?
The pipeline is blocked.
What is the expected correct behavior?
The pipeline should skip the job and continue running the next stages
Possible fixes
The problem seems to be the fact that the configuration uses rules.