是否可以在 gitlab-ci.yml 中将变量值从 job1 传递到 job2 标签。
我尝试了以下方法
job1:
stage:
build
tags:
[BUILD-POOL]
script:
- echo "BUILD_MACHINE=10.15.63.4" >> build.env
artifacts:
reports:
dotenv: build.env
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
job2:
stage:
test
tags:
- "$BUILD_MACHINE"
script:
- echo "job2 test"
needs:
- job1
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
我正在尝试这个,因为在 job1 中我使用
tags:[BUILD-POOL]
它将选择一个可用的免费虚拟机。
所以我想在构建 job1 的同一个虚拟机中构建 job2。
但是对我来说,上面提到的代码IP没有分配给job2中的
tags
。
任何建议/帮助将不胜感激。
我认为你的问题将通过 sticky runners 来解决,这是 GitLab 中的一个开放问题。
这可以通过将值存储到沿着管道传递的工件文件的额外步骤轻松完成。
job1:
stage: one
artifacts:
paths:
- myvariables.properties
script:
- echo "Store value hello to foo variable in bash properties file which is set to be passed as artifact in pipeline"
- echo "foo=hello" > myvariables.properties
job2:
stage: two
script:
- echo "job receives the artifact files which was set to include myvariables.properties file. Now read the file in as (bash) source"
- . myvariables.properties
- echo "foo value is ${foo}"
您不需要使用 bash 源或变量文件格式。您也可以使用:
echo "hello" > filex
并使用该值
$(cat filex)