Add an example .gitlab-ci.yml for the use case with Pipelines for merge requests and exclude a specific branch
Copied from gitlab-foss#15310 (comment 226748230).
Hi guys, I hope this is a good place for a small question. I need to run a pipeline for all merge requests except cherry picks and mass updates (which have a specific branch name prefix). I used the following code:
test: only: [ merge_requests ] except: [ /^(cherry-pick|mass-update)-.*/ ]
And it seems to not work. What an I doing wrong?
It seems we don't have an example in documentation for this common use case. We should clarify it with the solution.
MR refs are a bit special than ordinary branch refs e.g.
refs/merge-requests/:iid/head
notexample
as a feature branch. You'd need to useonly:variables
withCI_COMMIT_REF_NAME
predefined variables in this case, e.g.test: only: [ merge_requests ] except: variables: $CI_COMMIT_REF_NAME =~ /^(cherry-pick|mass-update)-.*/