I want to trigger gitlab ci pipeline only when 1 of the below 2 conditions are met.
- When PR get merged in main/master branch from any other branch. OR
- When commit message contains
BUILD_CONTAINER_IMAGE
string
I want to trigger gitlab ci pipeline only when 1 of the below 2 conditions are met.
BUILD_CONTAINER_IMAGE
stringYou should be able to use a set of workflow rules:
That would be in your case:
rules:
- if: '$CI_COMMIT_MESSAGE =~ /BUILD_CONTAINER_IMAGE/'
when: always
# pipeline should run on merge request to master branch
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'master'
when: always
# pipeline should run on merge request to main branch
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'main'
when: always
- when: never