Prefilled variables on manual pipelines not working properly with include:rules:if

Summary

When working on Prefilled variables for manual pipelines, variables are not showing properly if exact matching is used in the include:rules:if criteria. For example, given the following if conditions, only one of them will work.

include:
  - local: gitlab-configs/custom-inputs-nonprod.yml
    rules:
      #- if: $CI_COMMIT_BRANCH == "dev" # will not work
      #- if: $CI_COMMIT_BRANCH =~ /^dev$/ # will not work
      - if: $CI_COMMIT_BRANCH =~ /dev/ # will work

Steps to reproduce

  1. Create a project.
  2. Create gitlab-configs/custom-inputs-nonprod.yml and set the following.
variables:
  VARIABLE1:
    value: "staging"
    options:
      - "production"
      - "staging"
      - "canary"
    description: "The deployment target. Set to 'staging' by default."

  VARIABLE2:
    value: "alpha"
    options:
      - "alpha"
      - "bravo"
      - "charlie"
    description: "The deployment area. Set to 'alpha' by default."
  1. Create a .gitlab-ci.yml with the following settings.
include:
  - local: gitlab-configs/custom-inputs-nonprod.yml
    rules:
      - if: $CI_COMMIT_BRANCH == "dev" # will not work
      #- if: $CI_COMMIT_BRANCH =~ /^dev$/ # will not work
      #- if: $CI_COMMIT_BRANCH =~ /dev/ # will work

stages:          # List of stages for jobs, and their order of execution
  - build

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Compiling the code..."
    - echo "|${CI_COMMIT_BRANCH}|"
  1. Create a dev branch and try manually running the pipeline.
  2. Observe that the global variables expected to be prefilled are not visible.

Example Project

https://gitlab.com/kballon-bug-report/zd585383_prefill_variable_manual_pipeline

What is the current bug behavior?

Prefilled variables are not visible if using exact matching in include:rules:if

What is the expected correct behavior?

Prefilled variables are visible if using exact matching in include:rules:if

Relevant logs and/or screenshots

  • Using exact matching - if: $CI_COMMIT_BRANCH == "stage" and - if: $CI_COMMIT_BRANCH =~ /^stage$/ were tested.

Screenshot_2024-11-22_at_9.13.44_AM

  • Using regular expression if: $CI_COMMIT_BRANCH =~ /dev/

Screenshot_2024-11-22_at_9.13.52_AM

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by 🤖 GitLab Bot 🤖