1

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

1 Answers1

1

You 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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250