So I am looking through the gitlab ci documentation for passing variables to other jobs. However, how would I pass more than one? And how would I access more than one?
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
CodePudding user response:
You can save several values to the artifact and source it in a following job:
build:
stage: build
script:
- echo "BUILD_VERSION=hello" >> build.env
- echo "ANOTHER_VARIABLE=world" >> build.env
artifacts:
reports:
dotenv: build.env
deploy:
stage: deploy
script:
- source build.env
- echo "$BUILD_VERSION" # Output is: 'hello'
- echo "$ANOTHER_VARIABLE" # Outpur is 'world'
dependencies:
- build
Or if you need to export the variables in the environment, replace the source
command by the following one:
script:
- export $(cat build.env | xargs)