Add CI_UPSTREAM_PROJECT_ID to pipeline predefined variables
What does this MR do and why?
This MR introduces CI_UPSTREAM_PROJECT_ID as a new pre-pipeline predefined variable for multi-project pipelines.
It lets a downstream pipeline know which upstream project triggered it, without having to manually pass a custom variable.
This MR:
- Adds a
downstream_predefined_variablesmethod toGitlab::Ci::Variables::Downstream::Generator- When
bridge.triggers_cross_project_pipeline?is true, stores the upstream project ID inCI_UPSTREAM_PROJECT_ID.
- When
References
Related to #377694
How to set up and validate locally
-
In your GDK instance, create two projects (or reuse existing ones):
- an upstream project
- a downstream project
-
In the downstream project, create a
.gitlab-ci.ymllike:stages: - test print_upstream_vars: stage: test script: - echo "CI_UPSTREAM_PROJECT_ID=$CI_UPSTREAM_PROJECT_ID" - echo "CI_UPSTREAM_PIPELINE_ID=$CI_UPSTREAM_PIPELINE_ID" - echo "CI_UPSTREAM_JOB_ID=$CI_UPSTREAM_JOB_ID" -
In the upstream project, create a
.gitlab-ci.ymlthat triggers the downstream project via a bridge job, for example:stages: - trigger trigger_downstream: stage: trigger trigger: project: <your-namespace>/<downstream-project-path> strategy: depend -
Run a pipeline in the upstream project (for example, by pushing a commit or using Run pipeline in the UI).
-
When the downstream pipeline is created and the
print_upstream_varsjob runs, open the job log.
Expected result
-
CI_UPSTREAM_PROJECT_IDis set to the ID of the upstream project. -
CI_UPSTREAM_PIPELINE_IDis set to the ID of the upstream pipeline that triggered the bridge. -
CI_UPSTREAM_JOB_IDis set to the ID of the bridge job in the upstream pipeline. - All three variables are available as predefined variables in the downstream job’s environment.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.