Need a way to differentiate between manually triggering pipeline and Merge request events

I want to restrict the automatic creation of a pipeline as much as possible, as our pipelines take quite long and we have very limited resources.

A pipeline should therefore only be created if done manually or a push occurs on a specific branch. The thing I’m having troubles with is the “if done manually”-part.

Merge request events all seem to trigger the pipeline automatically. I’d like to stop that, which is easily done by checking if $CI_PIPELINE_SOURCE == "merge_request_event". However, manually pressing the “Run Pipeline”-Button on the Merge Request page also counts as a merge_request_event.
I’ve found no way to differentiate these two cases.

The more common case a pipeline is triggered on accident that way is when we’re creating a merge request. So I’d like to either disable that those events will be sent (or trigger a pipeline) or want some way to differentiate between manually starting the pipeline on the MR page and all other MR events.

Can anybody help me with that?


In the rules syntax you can say:

   - if $CI_PIPELINE_SOURCE == "web":
     when: never

There’s a full list of pipeline sources here.

It’s also worth taking a look through the [pre-defined variables for MR pipelines(Predefined variables reference | GitLab) which may also be of use to you.



Thanks for your help!
I already took an extensive look at those sources and also ran the pipeline once with a MR created event and once with the button and in both scenarios outputted all the available environment variables. Unfortunately, I couldn’t find any differences between those that would help me differentiate the use cases.

The $CI_PIPELINE_SOURCE is only web for the “Run Pipeline”-Button in the CI/CD > Pipelines section.
As written here in the comment: Merge requests API | GitLab the “Run Pipeline”-Button in the Merge Requests uses the Merge Request API and therefore the source is also categorized as merge_request_event.

Any further help would be greatly appreciated! :slightly_smiling_face:

Ah, my apologies, I had assumed you meat the “run pipeline” button!

No problems. I mean it is also the “Run pipeline” Button. But for some reason the “Run Pipeline” Button in the Merge Request page behaves differently to the “Run Pipeline” Button on the “Pipeline” Page. If they’d use the same API call I wouldn’t have this problem :frowning_face:

Sounds like it would be a good idea to add an issue for this, if there isn’t one already. The issues board is here.

Thank you! I created this issue: Need a way to differentiate between manually triggering pipeline and Merge request events (#324754) · Issues · / GitLab · GitLab