In order to stop the current default Gitlab behaviour of starting pipelines on branch creation I am trying to add a check in each job so that only merge requests trigger jobs when they have changes.
This is what I got so far:
rules:
- if: '[$CI_PIPELINE_SOURCE == "merge_request_event"] && [! git diff-index --quiet HEAD --]'
I am not quite familiar with bash which is surely the problem because I am currently encountering a 'yaml invalid' error :d
PS: Is there maybe a better way to do this instead of adding the check to each task?
i don't know if it can be useful, but Gitlab-ci provide the
onlyjob keyword that you can combine withchangesand insert a path to files, in this way you can execute jobs only if there are changes on the code you are interested on.Example
DOC: https://docs.gitlab.com/ee/ci/yaml/#onlychanges--exceptchanges