Wrong evaluation of variable passed by parent to child pipeline

Hello!

I’m experiencing a strange behavior with my parent-child pipeline setup when passing a variable to the child pipeline.

  • this var is empty by default, if it has any value, a job in the child pipeline triggers
  • rule of the job worked fine when the child pipeline was used by itself, before I introduced the parent-child flow
  • I debugged the same evaluation as the job rule has, the var considered empty everywhere, the job still triggers

Configuration

Parent CI config:

stages:
  - debug
  - triggers

variables:
  TRIGGER:
    value: ""
    description: "Add some value to trigger mysterious job"

debug:
  stage: debug
  script:
    - |
      if [[ $TRIGGER=~ .+ ]]; then
        echo "its not empty"
      else 
        echo "its empty"
      fi

trigger_flow_a:
  stage: triggers
  trigger:
    include: .flow-a-gitlab-ci.yml
  variables:
    TRIGGER: $TRIGGER # same with "$TRIGGER" or "${TRIGGER}"
  rules:
    if: $CI_COMMIT_BRANCH == "develop" && $CI_COMMIT_MESSAGE =~ /.*\[flowA\].*/

Affected job in child

mysterious-job:
  stage: mysterious
  before_script:
    - |
      if [[ $TRIGGER=~ .+ ]]; then
        echo "its not empty"
      else 
        echo "its empty"
      fi
  script:
    - echo "..."
  rules:
    - if: $CI_COMMIT_BRANCH == "develop" && $TRIGGER=~ /.+/

Versions

  • Self-managed

  • GitLab Community Edition v16.8.1

  • /w K8s runners

Debugging

Debugging in the parent with a non empty TRIGGER shows that the value is not empty. On the other hand, the same condition evaluates to false in the child. Even with that, the job is triggered.
Looks like the variable is not passed properly, but then why does the job run?

Thank you in advance,
David

*UPDATE: made some edits to the original post as I realized regex syntax differs in script and rules blocks

Actual problem and solution found!
Bug(?)
It’s pretty weird that the problem occurs only in case of an empty variable:

  • if I add any value to TRIGGER, it’s passed and visible in the child pipeline (and the affected job triggers ofc.)
  • if TRIGGER is empty, debug logs in the child shows that it’s empty indeed, but the job still triggers

Solution:
Using trigger:forward:pipeline_variables: true and NOT passing variable TRIGGER in the trigger job, the variable works in the child as expected :white_check_mark:

variables:
  TRIGGER:
    value: ""
    description: "Add some value to trigger mysterious job"

trigger_flow_a:
  stage: triggers
  trigger:
    include: .flow-a-gitlab-ci.yml
    forward:
      pipeline_variables: true
  variables:
    OTHER_VAR: "also_visible_in_child"
  rules:
    if: $CI_COMMIT_BRANCH == "develop" && $CI_COMMIT_MESSAGE =~ /.*\[flowA\].*/