CI: jobs with rules can prevent jobs without rules being created

Summary

Jobs in a pipeline may not get created if other jobs - which have rules assigned to them - get created.

I noticed it specifically testing some jobs which tested merge request variables:

    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" &&
          $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != "release"'

These issues seem to be in the same kind of space, they're the best hits I found,

Workaround: add a rule to the other jobs that'll always return success, such as testing for a variable which is always present.

  rules:
    - if: '$CI'

Steps to reproduce

  • New repo on gitlab.com
  • Create master with readme.
  • Push an identical branch called release
  • I've changed the default branch and set protection on branches like this; I doubt it's relevant.

image

  • settings/general

image

stages:
  - workflow-protection
  - test

testjob1:
  stage: test
  script:
    - echo "${CI_JOB_NAME}"

invalid-source-for-merge-to-master:
  stage: workflow-protection
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" &&
          $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != "release"'
  script:
    - /bin/false

image

image

stages:
  - workflow-protection
  - test

testjob1:
  stage: test
  rules:
    - if: '$CI'
  script:
    - echo "${CI_JOB_NAME}"

invalid-source-for-merge-to-master:
  stage: workflow-protection
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" &&
          $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != "release"'
  script:
    - /bin/false

image

Example Project

https://gitlab.com/bprescott-support/testing/issue194129-cirules

What is the current bug behavior?

The creation of the job with the rule interferes with the creation of the other job.

What is the expected correct behavior?

One job should always be created, and when the rule triggers, the second job as well.

I found it trying to get larger (three stage/three job) pipelines to build. the 'guard' job I was trying to demonstrate would wipe out the entire pipeline.

Relevant logs and/or screenshots

(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise.)

Output of checks

The bug was found on gitlab.com

Results of GitLab environment info

n/a

Results of GitLab application Check

n/a

Possible fixes

(If you can, link to the line of code that might be responsible for the problem)

Edited by 🤖 GitLab Bot 🤖