Workflow:rules - I don't get it

Hi together,

I have a CI stage which should NOT run when “this is a merge request from develop to main”. I thought I try it with workflow or even with rules for the give job.

workflow:
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "develop" && $CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never

But when I enable this, (in this case it’s for the whole pipeline) nothing runs. Also I can’t trigger a “Run Pipeline” on a specific MergeRequest which is a classic /feature/foo-bar -> develop

I’m strugglein…

Thanks for support,

Tom

So, the way I would have done this would be:

workflow:
  rules:
    - if: '$CI_MERGE_REQUEST_ID && '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "develop"'
      when: never
    - when: always

Do you have other workflow rules in your CI config, or is that the only one?

Hi Snim2,

thanks! I will try it later. No, for now it’s the only one.

1 Like

As per the docs

When no rules evaluate to true, the pipeline does not run.

Yes! The final - when: always did the job!! Thanks folks!

1 Like