Sharath Prakash
Sharath Prakash

Reputation: 326

Rules changes with CI_PIPELINE_SOURCE does not work

I am trying to limit gitlab to run a job only when the trigger is a merge request or subsequent pushes to the source branch.

Below is my gitlab-ci yaml enter image description here

But even if i change gilab-ci.yaml the pipeline triggers, also it runs when i change the test-file.sh file inside awe/src/.

I tried it to trigger a downstream-pipeline using these rules, it didn’t work. I also tried to run a local script as well. But no luck.

The rules config

enter image description here

I also tried to add the source as push event since sometimes the subsequent commits to a branch with an active MR is treated as push event

In all scenarios, the pipeline triggers everytime i make a change, irrespective of whether the change is made to the folder specified or not. Any help will be appreciated

Upvotes: 1

Views: 2190

Answers (1)

bhito
bhito

Reputation: 2673

To limit the execution to only certain scenarios like push or merge request you need to add an if condition:

rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

One thing to be aware of is that you cannot mix only and rules in the same job, as the docs state

rules replaces only/except and they can’t be used together in the same job. If you configure one job to use both keywords, the GitLab returns a key may not be used with rules error.

Refer to this link for a commonly used set of rules that is provided in the documentation and may be helpful for you.

Upvotes: 0

Related Questions