Inconsistent variable behavior in multi-project pipeline

This was just a headache! Thanks for the help @balonik and @magnum

Another way of handling this, that is less confusing… but possibly more work is to eschew the unwrapping that gitlab does and do it in bash (which collapses to the end result).

Then you pass it as an artifact to the trigger job. That way you make 100% it is unwrapped on the parent, it will just take an extra job, or adding a bit to the after_script of a previous job.



previous-job:
  variables:
    ENV_FILE: .dotenv
  script:
    - echo 'job'
  after_script:
    - echo "UPSTREAM_PIPELINE_IID=$CI_PIPELINE_IID" | tee "$ENV_FILE" >> $GITLAB_ENV
    - echo "UPSTREAM_PROJECT_NAME=$CI_PROJECT_NAME" | tee -a "$ENV_FILE" >> $GITLAB_ENV
  artifacts:
    when: on_success
    expire_in: "1 hour"
    reports:
      dotenv: $ENV_FILE



trigger-job:
  dependencies:
    - previous-job
  variables:
    UPSTREAM_PIPELINE_IID: $UPSTREAM_PIPELINE_IID
    UPSTREAM_PROJECT_NAME: $UPSTREAM_PROJECT_NAME
  trigger:
    project: downstream/project
    strategy: depend