There is a known problem that in Gitlab it's not possible to avoid pipeline duplication in some scenarios.
Let's assume you combine merge and branch pipelines. You can follow the Gitlab guideline or here is an improved one:
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- if: '$CI_COMMIT_BRANCH'
When you push and then you open a MR immediately it's not possible to avoid getting a second pipeline (though if you have one open then it's not an issue).
git push -o merge_request.create
Here is a script that supposed to be run after the push to cancel the duplication.
- Create an alias in your bash profile / .zshrc file, e.g.:
alias cancel-branch-pipeline="sh ~/gitlab/gitlab-cancel-branch-pipeline.sh"
- Set you Gitlab personal access token with scopes
api
andread_api
asGITLAB_TOKEN
environment variable (you can set it in your bash profile file to have in every session:export GITLAB_TOKEN=<your-token>
) - Call it after with the alias anytime you push, and you want to open a MR:
$ cancel-branch-pipeline