You can still pass it to other jobs or you can use it as an artifact and pass it for later jobs or pipelines. You can also consider saving it as a project variable if you want.
You can pass environment variables from one job to another job in a later stage. These variables cannot be used as CI/CD variables to configure a pipeline, but they can be used in job scripts.
In the job script, save the variable as a .env file.
Save the .env file as an artifacts:reports:dotenv artifact.
Set a job in a later stage to receive the artifact by using the dependencies or the needs keywords.
The later job can then use the variable in scripts.
For example, with the dependencies keyword:
build:
stage: build
script:
- echo "BUILD_VERSION=hello" >> build.env
artifacts:
reports:
dotenv: build.env
deploy:
stage: deploy
script:
- echo "$BUILD_VERSION" # Output is: 'hello'
dependencies:
- build
For example, with the needs keyword:
build:
stage: build
script:
- echo "BUILD_VERSION=hello" >> build.env
artifacts:
reports:
dotenv: build.env
deploy:
stage: deploy
script:
- echo "$BUILD_VERSION" # Output is: 'hello'
needs:
- job: build
artifacts: true