Problem to solve
*I need to pass a variable that was generated in a job to all descendant jobs and stages.
I am generating the variable in a ci component, so I would like it to be available to all jobs that want to use it, without those jobs having to add anything other than the variable usage. So I would like to avoid using needs or dependencies.
Using dotenv report artifacts ALMOST does exactly what I need, however, the variables are only available in the direct child stage and not any grandchild+ stages.*
Steps to reproduce
The following configuration is an abbreviated representation of my real ci configs.
In reality the component is supposed to be included multiple times and the generator job and resulting variables should support naming via component inputs, which makes using needs annoying.
Configuration
# my ci component
generate-variable:
stage: .pre
script:
- GENERATED_VARIABLE=generate-variable
- echo "GENERATED_VARIABLE=$GENERATED_VARIABLE" >> my-comp.env
artifacts:
reports:
dotenv: my-comp.env
# my project gitlab-ci.yml
include:
- component: gitlab.foobar.xyz/devops/mycomponent/mycomp@main
stages:
- build
- deploy
build-job:
stage: build
script: echo $GENERATED_VARIABLE # works
deploy-job:
stage: deploy
script: echo $GENERATED_VARIABLE # does not work
deploy-job-with-needs:
stage: deploy
needs: generate-variable
script: echo $GENERATED_VARIABLE # works, but becomes annoying to communicate to component users when inputs are involved
Afterword
Is it possible to pass a variable generated by a job to ALL subsequent jobs without adding something to each subsequent job?
Unfortunately using needs in default is not supported, so I cannot add it to every job that way.