Gitlab
CICD, Rules and pipelines
When using the rules parameter in a CICD pipeline in Gitlab, the runner will execute a second pipeline run only including the immediate jobs with a rules parameter included:
job01:
...
rules:
- 'something'
job02:
...
rules:
- 'else'
job03:
...
This ends up in two pipelines:
- Pipeline 1:
job01, job02, job03
in the default pipeline context - Pipeline 2:
job01, job02
in the MR pipeline context.
When using rules
in Pipeline 2, only the jobs containing the rules
parameter are used. In combination with needs
dependencies might not be met and the pipeline run in the MR context can fail.
Found errors in your .gitlab-ci.yml:
* 'job x' job needs 'job y' job
but 'job y' is not in any previous stage 'job x' job needs 'job z' job
but 'job z' is not in any previous stage
The reason why the usage of "rules" starts its own pipeline-run is unclear.
The suggested solution is to either
- To disable the run of pipelines in the MR context on a per job basis or
yaml
job x:
...
rules:
- if: $CI_MERGE_REQUEST_ID
when: never
- when: always
- to disable the run of pipelines in the MR context globally for the complete pipeline configuration for a given project.
```yaml
workflow: rules: - if: $CI_MERGE_REQUEST_ID when: never - when: always ```