如何计算阶段“create_profile”中的变量,然后应在下一阶段“trigger_upload”中接管。
我的第二个管道“git-project/profile-uploader”在“trigger_upload”阶段被触发应该得到这个变量。
这是我目前的方法:
---
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
目前管道“git-project/profile-uploader”按预期获得PROFILE_NAME“hello world”,PROFILE_VERSION 的值为“none”。 PROFILE_VERSION 应具有值“0.1.0” - 在阶段“create_profile”中计算。
答案 0 :(得分:1)
您需要通过 dotenv
报告工件传递变量,如本 answer 中所述。因此应用于您的示例,管道将如下所示:
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