Variables from dotenv are passed as trigger variables to downstream pipeline - this is not documented
Background
According to the GitLab documentation, the way to pass dotenv variables to downstream pipeline is to add a job in the downstream pipeline with the needs
keyword.
Copied from the documentation:
test:
stage: test
script:
- echo $BUILD_VERSION
needs:
- project: my/upstream_project
job: build_vars
ref: master
artifacts: true
This indeed works, and useful since it is the only way to pass variables to child pipeline while keeping the variables priority. See #281201 (closed)
The behavior I see
The actual behavior that I see is that this needs
in the child pipeline is not needed.
The behavior that I see is that:
- A job in the parent pipeline publishes a dotenv file
- A job in the next stage in the parent pipeline uses
trigger
to trigger a child pipelines - All the variables from the dotenv file become trigger variables for the child pipeline
Example:
Parent pipeline:
build_vars:
stage: build
script:
- echo "NEW_VAR=new_value" >> build.env
artifacts:
reports:
dotenv: build.env
trigger_job:
trigger:
include:
- local: child-pipeline.yml
Child pipeline:
print_vars:
stage: test
script:
- echo "NEW_VAR=$NEW_VAR"
It prints NEW_VAR=new_value
.
when I use GitLab API to get the pipeline variables of the child pipeline, I see that the variable NEW_VAR
is there with the value new_value
.
The questions
I have no complains about this behavior, this is actually convenient since GitLab do not fix the issue of variables priority when passing variables to child pipeline.
My requests:
-
Is the expected behavior? I want to know if I can use this feature without worrying it will be changed in the future.
-
If it is the intended behavior, I suggest to modify the documentation in https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#pass-dotenv-variables-created-in-a-job to say that the
job
needs` in the child is not needed.