Jenkins管道:在stage1中,从文件中读取编号,在stage2中**,在**节点名称内使用该编号 [英] Jenkins pipeline: in stage1, read number from file, in stage2, **within** node name, use that number
问题描述
a>
我现在坚持必须将数字设置为节点名称的一部分,其中此数字包含在另一个节点上的文件中。
例如,如果属性文件包含数字6,则必须在名为DEV-SME-6的节点上运行作业。
有没有办法让我:在stage1中,从主节点上的文件中读取数字,如下所示:
Env_number = readFile'file_containing_an_integer_between_2_and_7.txt'
<然后在stage2中 节点名称中,使用该数字指定节点名称的一部分,如下所示:
node('DEV-SME- $ Env_number')
??
这不适用于unstash(试图在指定节点名称之前先取消flush命令,这会给我一个错误:FilePath.hudson丢失了
我现在的代码在尝试了一些东西之后,就像这样:
stagefirst stage
节点('master'){
尝试{
env.Env_number = sh'echo DEV $(cat file_containing_an_integer_between_2_and_7.txt'
catch(error)
echofailed设置变量Env_number
($'$ Env_number}'){
尝试{
command1
command2
} }
这给了我一个没有标签为空的节点'null'
成功!没有sh脚本,使用readFile:
pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' b尝试{
env.Env_number = readFile'file_containing_an_integer_between_2_and_7.txt'
catch(error)
echo无法设置变量Env_number
}}
阶段第二阶段
节点(DEV $ {Env_number}){
尝试{
command1
command2
}}
To continue this: Jenkins pipeline stages - passing whole file
I'm now stuck with having to set a number as part of a node name, where this number is contained within a file on another node.
E.g, if a properties file contains the number 6, I have to run a job on a node named DEV-SME-6.
Is there a way for me to: in stage1, read the number from a file on the master node, something like this:
Env_number = readFile 'file_containing_an_integer_between_2_and_7.txt'
then in stage2, within the node name, use that number to specify part of the node name like this:
node('DEV-SME-$Env_number')
??
This doesn't work with unstash (trying to unstash before specifiying a node name in a stage gives me an error: FilePath.hudson is missing
My current code, after trying some stuff, is something like this:
stage "first stage"
node ('master'){
try{
env.Env_number = sh ' echo DEV$(cat file_containing_an_integer_between_2_and_7.txt '
catch(error)
echo "failed to set variable Env_number "
}}
stage "second stage"
node('${Env_number}') {
try{
command1
command2
}}
This gives me a "no nodes with the label 'null' "
Success! without sh scripts, with readFile:
stage "first stage"
node ('master'){
try{
env.Env_number = readFile 'file_containing_an_integer_between_2_and_7.txt'
catch(error)
echo "failed to set variable Env_number "
}}
stage "second stage"
node("DEV${Env_number}") {
try{
command1
command2
}}
这篇关于Jenkins管道:在stage1中,从文件中读取编号,在stage2中**,在**节点名称内使用该编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!