I would like to pass a dotenv variable to a downstream pipeline. The variable is “created” during build, because the version is extracted from a source file.
I have the exactly same problem. I guess it is related to the fact that jobs with the trigger-key are treated as ‘trigger-bridge-jobs’ with some limitation: https://docs.gitlab.com/ee/ci/multi_project_pipelines.html#limitations
Most important one: They are not run on a Gitlab-Runner. My guess is the automatic reading of the dotenv-Artifact is normally handled by the Runner.
Inherited variables take precedence over certain types of new variable definitions such as job defined variables
The section below that in the docs gives an example:
build:
stage: build
script:
- echo "BUILD_VARIABLE=value_from_build_job" >> build.env
artifacts:
reports:
dotenv: build.env
deploy:
stage: deploy
variables:
BUILD_VARIABLE: value_from_deploy_job
script:
- echo "$BUILD_VARIABLE" # Output is: 'value_from_build_job' due to precedence
environment: production
It seems that redeclaring variables would not have an effect, since “inherited” variables take precedence. It’s not exactly clear from this section of the docs why loading dotenv files is termed inheritance, but I imagine the dotenv functionality in gitlab is modeled on passing environment variables to child processes in shell scripts.