Passing dotenv variables to downstream pipeline

Hi,

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.

prepare-build:
   stage: prepare_build
   script:
     - export VERSION=$(cat package.json | jq -r .version)
     - echo "VERSION=$VERSION" >> build.env
   artifacts:
     reports:
       dotenv: build.env

In the next build steps the variable VERSION is available and contains the correct version value. Everything is fine so far.

But in the last step I want to pass this variable to a downstream pipeline:

trigger-deployment:
  stage: trigger_deploy
  variables:
    VERSION: $VERSION
  trigger:
     project: my/project

This doesn’t work. The variable VERSION contains the string $VERSION, not the actual version number as in all build steps before.

Is it not possible to pass dotenv variables to downstream pipelines? If not, is there any other way to do it?

Thanks for your help.

Best regards,
Daniel

Nobody? I can’t be the only one having this “issue” …

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.

So for now you probably have to trigger the downstream pipeline manually: https://docs.gitlab.com/ee/ci/triggers/README.html#when-used-with-multi-project-pipelines
This will allow you to pass variables yourself: https://docs.gitlab.com/ee/ci/triggers/README.html#making-use-of-trigger-variables

This sounds like exactly the problem I’ve encountered too. I created https://gitlab.com/gitlab-org/gitlab/-/issues/223224 for it.