We have a normal repository, with some code and tests.
One job has 'rules' statement:
rules:
- changes:
- foo/**/*
- foo_scenarios/**/*
- .gitlab-ci.yml
The problem is that presence of rules
causes Gitlab to run 'detached pipeline', which wasn't my intention, and it's annoying. Is there any way to disable those 'detached' pipelines, but keep the rules
section in place?
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
- changes:
- foo/**/*
- foo_scenarios/**/*
- .gitlab-ci.yml
when: always
I have not tested this, but I believe this is what you are looking for. This page and this one too are both easily navigable and are very helpful for finding the answer to basic gitlab-ci.yml questions.
Edit- Gitlab will evaluate the rules in order, and it stops evaluating subsequent rules as soon as one of the conditions are met. In this case, it will evaluate if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
first, and if it evaluates to true, no more rules will be checked. If the first rule evaluates to false, it will move on to the next rule.
Things are actually more complicated as it depends from case to case. So this solution may work for you, but someone else may need to tweak it a bit.
Here is my understanding of it. As soon as you add rules: to your pipeline, you will override some defaults which prevent the merge request pipeline from begin created.
The solution suggested by @Benjamin works, but as you have noticed, needs to be added to every job. So a lot of repeated configuration for most jobs.
I would suggest looking into workflow: that allows you to define a default behavior. You will need rules only for the jobs that have special rules.
Here is an example:
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
If you wish to go a bit deeper into this behavior, I have written an article about this (friend link for anyone without a Medium subscription):
Fix GitLab CI Duplicate Pipelines in Merge Requests when Using rules:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With