How can I calculate a variable in the stage "create_profile", which should then be taken over in the next stage "trigger_upload".
My second pipeline "git-project/profile-uploader" which gets triggered in the stage "trigger_upload" should get this variable.
This is my current approach:
---
variables:
APPLICATION_NAME: "helloworld"
APPLICATION_VERSION: "none"
create_profile:
stage: build
script:
# calculate APPLICATION_VERSION
- APPLICATION_VERSION="0.1.0"
- echo "Create profile '${APPLICATION_NAME}' with version '${APPLICATION_VERSION}'"
artifacts:
paths:
- profile
trigger_upload:
stage: release
variables:
PROFILE_NAME: "${APPLICATION_NAME}"
PROFILE_VERSION: "${APPLICATION_VERSION}"
trigger:
project: git-project/profile-uploader
strategy: depend
At the moment the pipeline "git-project/profile-uploader" gets the PROFILE_NAME "hello world" as expected and the PROFILE_VERSION has the value "none". PROFILE_VERSION should have the value "0.1.0" - calculated in the stage "create_profile".
An alternative is to use Gitlab Variables. Go to your project page, Settings tab -> CI/CD, find Variables and click on the Expand button. Here you can define variable names and values, which will be automatically passed into the gitlab pipelines, and are available as environment variables there.
Passing environment variables (or other data) between CI jobs is now possible. By using the dependencies keyword (or needs keyword for DAG pipelines), a job can inherit variables from other jobs if they are sourced with dotenv report artifacts.
You need to pass the variable via dotenv
report artifacts as described in this answer. So applied to your example the pipeline will look like this:
variables:
APPLICATION_NAME: "helloworld"
APPLICATION_VERSION: "none"
stages:
- build
- release
create_profile:
stage: build
script:
# calculate APPLICATION_VERSION
- echo "APPLICATION_VERSION=0.1.0" >> build.env
- echo "Create profile '${APPLICATION_NAME}' with version '${APPLICATION_VERSION}'"
artifacts:
paths:
- profile
reports:
dotenv: build.env
trigger_upload:
stage: release
variables:
PROFILE_NAME: "${APPLICATION_NAME}"
PROFILE_VERSION: "${APPLICATION_VERSION}"
trigger:
project: git-project/profile-uploader
strategy: depend
needs:
- job: create_profile
artifacts: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With