Search code examples
gitlabyamlgitlab-ci

GitLab CI "when: never" under "rules" doesn't stop pipeline from triggering


GitLab v. Enterprise Edition 15.0.5-ee
I have some stages defined and I need rules that would work like a conjunction.
But I have a problem that simply put:

rules:
 - if: ! A
   when: never
 - if: B

doesn't work (like it should according to https://docs.gitlab.com/ee/ci/jobs/job_control.html):
it runs a pipeline despite (! A) being true

but

rules:
 - if: A && B

does work (pipeline doesn't run). And second options is not preferable and in other case I have with exists it's not possible (correct me if I'm wrong).

Is there a way to work around it?

EDIT 1:

ok I worked around the exists (checking if variable is null) part but I still want to have reusable code.

I'm using reference:

.rules:
  rules:
    - if: ! A
      when: never
    - exists:
        - "$ex"
      when: never

rules:
    - !reference [ .rules, rules ]
    - if: $var =~ /^.*abcd.*$/

because aliases and anchors don't seem to work here. And if I want this structure then I figured that I need this when: never part for it to work. Therefore the original question about it. Without reference it doesn't work either so it doesn't matter unless I can do something to inject the rules in an if.


Solution

  • I think the boolean not operator does not exist, see this comment. Try

    rules:
     - if: A != true
       when: never
     - if: B