Rules processing and CI_PIPELINE_SOURCE

We are trying to leverage the rules keyword in lieu of only/except. We have simple goals: Do not run a job on test and production branches, and do not run if the pipeline is scheduled. This is what I came up with:

    - if: '$CI_COMMIT_REF_NAME == "production" || $CI_COMMIT_REF_NAME == "test"'
      when: never
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never

When this ci is present, it does not run the job when initated from the web. This does work:

    - if: '$CI_COMMIT_REF_NAME == "production" || $CI_COMMIT_REF_NAME == "test"'
      when: never
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"```

Why do I need to explicitly allow web based as `CI_PIPELINE_SOURCE`? I get the order of operation but I see nothing in the top ci from precluding a web based run of the job.

My only guess is to try `    - if: $CI_PIPELINE_SOURCE != "schedule"` and omitting the `never`, but I still do not understand why what I have does not work. Any pointers?

Hi @powellbc

this is described in the rules. First thing after the header:

Use rules:if clauses to specify when to add a job to a pipeline:

    If an if statement is true, add the job to the pipeline.
    If an if statement is true, but it’s combined with when: never, do not add the job to the pipeline.
    If no if statements are true, do not add the job to the pipeline. 

Your case is the last line. Since rules are evaluated in order specified, simply adding - when: on_success as last rule would make the job run.

1 Like

Thanks so much for the clarification. A little embarrassed I missed this critical bit, my only excuse being I was looking at some of the specific rules topics and missed the basics!

Interestingly it seems this would not have worked until fairly recently.

In any case thanks again @balonik.