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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With