Environment variables would not be inherited to the Trigger job from the dependent jobs(with artifacts.reports.dotenv)
Summary
I tried to follow the solution mentioned #22638 (closed) to carry the environment variables from one job to another, by using artifacts.reports.dotenv.
But in my case, the destination job is a job that just triggers another pipeline.
It seems the trigger jobs would not use the artifacts.reports.dotenv, unlike the normal job
Steps to reproduce
Just run the pipeline of the test-trigger-caller and check the dependant trigger output and see the values of TEST_CI_COMMIT_SHA, TEST_CI_PROJECT_NAME and TEST_CI_PROJECT_VERSION. The first two used the global environment variables which will be carried to the dependant triggered job, but the last one uses the variable stored in the first job(the job named after) which seems would not be carried over.
You can find the values and samples in the Example section.
Example Project
To help understand it better, I have two repositories:
-
test-trigger-caller: which is the starting point and is the main pipeline. It calls the pipeline on the caller repository -
test-trigger-callee: the pipeline which just prints 3 environment variables that we want to carry from the parent pipeline. Here we want to check whether all the variable has been carried from the callee pipeline or not! Eventually, I want to use those 3 variables to update a file in this repository.
The pipeline for the test-trigger-caller
stages:
- before
- triger-callee
- after
before:
stage: before
script:
- echo "executing before"
- export TEST_CI_PROJECT_VERSION="1.3.4"
- echo TEST_CI_PROJECT_VERSION="${TEST_CI_PROJECT_VERSION}" > variables.env
artifacts:
reports:
dotenv: variables.env
triger-callee:
stage: triger-callee
variables:
TEST_CI_COMMIT_SHA: ${CI_COMMIT_SHA}
TEST_CI_PROJECT_NAME: ${CI_PROJECT_NAME}
TEST_CI_PROJECT_VERSION: ${TEST_CI_PROJECT_VERSION}
trigger:
project: mip/pade/tests/pipeline/test-trigger-callee
# strategy: depend
branch: master
after:
stage: after
script:
- echo "executing after"
- echo ${TEST_CI_PROJECT_VERSION}
The pipeline for the test-trigger-callee
stages:
- catch-triggers
catch-triggers:
stage: catch-triggers
script:
- echo "this is executed"
- echo "TEST_CI_COMMIT_SHA:${TEST_CI_COMMIT_SHA}"
- echo "TEST_CI_PROJECT_NAME:${TEST_CI_PROJECT_NAME}"
- echo "TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}"
What is the current bug behavior?
When I take a look at the result of the pipeline in test-trigger-callee, I see this:
Created fresh repository.
Checking out bd7afa53 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo "this is executed"
this is executed
$ echo "TEST_CI_COMMIT_SHA:${TEST_CI_COMMIT_SHA}"
TEST_CI_COMMIT_SHA:92867e64f113cf00ec31df14b288d160cb49175e
$ echo "TEST_CI_PROJECT_NAME:${TEST_CI_PROJECT_NAME}"
TEST_CI_PROJECT_NAME:test-trigger-caller
$ echo "TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}"
TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}
Cleaning up file based variables
Job succeeded
Look at TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}. It seems I cannot use the generated environment variable used in the previous job(before in test-trigger-caller's pipeline).
But, when you take a look at the output of the after job in the test-trigger-caller pipeline, you could be able to see it properly, like:
executing after
$ echo ${TEST_CI_PROJECT_VERSION}
1.3.4
What is the expected correct behavior?
The trigger job(trigger-callee) in the test-trigger-caller pipeline should be able also to use the passed environment variable by artifacts.reports.dotenv.
Relevant logs and/or screenshots
Logs of the test-trigger-caller
before job
$ echo "executing before"
executing before
$ export TEST_CI_PROJECT_VERSION="1.3.4"
$ echo TEST_CI_PROJECT_VERSION="${TEST_CI_PROJECT_VERSION}" > variables.env
Uploading artifacts for successful job
Uploading artifacts...
variables.env: found 1 matching files and directories
Uploading artifacts as "dotenv" to coordinator... ok id=1304845 responseStatus=201 Created token=CLUFtMTF
Job succeeded
triger-caller job
N/A. The trigger job does not have any output
after job
$ echo "executing after"
executing after
$ echo ${TEST_CI_PROJECT_VERSION}
1.3.4
Job succeeded
Logs of the test-trigger-callee
catch-triggers job
$ echo "this is executed"
this is executed
$ echo "TEST_CI_COMMIT_SHA:${TEST_CI_COMMIT_SHA}"
TEST_CI_COMMIT_SHA:92867e64f113cf00ec31df14b288d160cb49175e
$ echo "TEST_CI_PROJECT_NAME:${TEST_CI_PROJECT_NAME}"
TEST_CI_PROJECT_NAME:test-trigger-caller
$ echo "TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}"
TEST_CI_PROJECT_VERSION:${TEST_CI_PROJECT_VERSION}
Cleaning up file based variables
Job succeeded