Reputation: 395
I would like gitlab-ci to ignore merge from a specific branch.
Example: I have 3 branches. master, development & test.
If I push the code directly or merge the code from any branch to master/development, the pipelines get executed.
Now, I don't want pipeline to get running when I merge from test branch specifically.
I would like to exclude merge from test branch to development or master.
Upvotes: 0
Views: 2922
Reputation: 510
This can be done by specifying an if-rule for the jobs you want to exclude. For example:
docker build:
script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
rules:
- if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != "test" || ($CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "test" and ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "development"))'
The 2 variables CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
and CI_MERGE_REQUEST_TARGET_BRANCH_NAME
are automatically defined only in the case of a merge request.
Upvotes: 1
Reputation: 2220
Gitlab CI does not have to verify "what" is being merged, only "where" it is being merged.
You could do it using script which uses git
commands (it allows to check both parents for merge commit). However, I advise you to do not do it. The reason is you can miss build for changes merged from not "test" branch.
E.g.
At this point, build started at p2 is cancelled by Gitlab, build started at p2 is cancelled by your script. As a result, required build is missing.
Upvotes: 0