0
votes

I want to have a pipeline that needs to run at each merge request. I would also like to have the ability to run that pipeline manually so that one can anticipate merge issues.

However, if I specify my jobs as

only:
  - merge_requests

when trying to run the pipeline manually, I am greeted with a

Pipeline cannot be run. No stages / jobs for this pipeline.

If I use workflows instead,

include:
  - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'

I am greeted with a different but equivalent

Pipeline cannot be run. Pipeline filtered out by workflow rules.

So how can I set up a pipeline that is required for merge requests but that could also be run manually by users on their feature branch?

2

2 Answers

4
votes

You should use rules instead of only/except as the later will be deprecated in the future.

But instead of configuring when every job should run you can use workflow and define for the whole pipeline when it should be created.

In your example the following workflow will create a pipeline if it is a merge-request and if the pipeline was manually triggered without a push.

For further reference you can take a look at the possible values for CI_PIPELINE_SOURCE if you want to change that in the future.

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_PIPELINE_SOURCE == "web"'
1
votes

Usually, I'd recommend using the newer rules statement instead of only, that way if you want to run it only manually in merge requests, I'd do something like the following:

enter image description here

The CI_PIPELINE_SOURCE is a default variable from Gitlab ci should be useful for your use case.