Combine gitlab ci rules if to only trigger a job when a push or merge is made to master branch

Viewed 1182

I`m new to Gitlab-CI and would like to trigger a script in Gitlab CI if changes are made to files in a defined folder and there has either been a push to the master branch OR some other branch has been merged into master. After reading the docs I think this could work:

    trigger_something:
      rules:
        - changes:
          - path2importantstuff/*
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
        - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"'
      script:
        - curl --data-urlencode "argString=-ExecutionMode 'Real Run'" 127.0.0.1:2220/api/11/job/47c7c848/run

Is it possible to combine if conditions like this? Are they combined with a logical OR? Can something be improved?

Thank you - all the best, Sacha

1 Answers

I was a bit late.

But here's your answer.

You were right, they combined with a logical OR, not AND.

Any of those IF hit will trigger the job.

Update: I'm working on gitlab ci configuration and this is the right behavior, I've tested

Related