Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI Rules - Run only on push to origin/master

I'm looking for a bit of an unusual use case, where I only run certain jobs after a push to origin/master. In practice, this only happens when a merge goes in so my first attempt at this was the following rule:

if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_BRANCH == "master"'

This didn't work though, presumably because the actual merge commit pushed to origin/master is not considered a merge_request_event.

Any way to achieve this?

Note: I don't simply use if: $CI_COMMIT_BRANCH == "master"' to avoid running on a push to a non-origin fork's master branch.

like image 936
Derek Avatar asked Mar 22 '26 16:03

Derek


1 Answers

I found a way to do this using the uniquely assigned PROJECT_ID gitlab variable (it's different for each fork). So the following works:

if: '$CI_PROJECT_ID == "<origin fork's project_id>" && $CI_COMMIT_BRANCH == "master"'

The project ID can be found in Settings on gitlab.

like image 169
Derek Avatar answered Mar 24 '26 23:03

Derek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!