具有多个值的单个参数-引用扩展选择的参数值 [英] Single parameter with multiple values - referencing extended-choice parameter values
问题描述
我在詹金斯(Jenkins)遇到以下情况.
I am stuck with the following situation in Jenkins.
一个工作需要建立多个 make
目标.这将通过每次运行多次 make
来实现,因为一次只允许一个目标.我想允许用户选择每次运行要构建的目标.
A job needs to build multiple make
targets. This will happen through multiple invocations of make
per run as it allows only 1 target at a time. I want to allow users to select which targets to build with each run.
我尝试了使用 extended-choice parameter
插件(多次选择),但无法弄清楚如何从中解析多个值,以及如何构造对 make 的调用代码>
I tried with extended-choice parameter
plugin (Multi-select), but could not figure out how to parse multiple values from it, and how to structure my call to make
有人可以帮我吗
推荐答案
扩展选择参数将始终将其选择的值列出为 TARGET = value1,value2
.充其量,您可以强制将值引用为 TARGET ="value1,value2"
Extended-choice parameter will always list its selected values as TARGET=value1,value2
. At best, you can enforce the values to be quoted like this TARGET="value1,value2"
您必须解析此 TARGET
值才能将其转换为所需的格式.
You have to parse this TARGET
value to get it into the format you want.
如果您可以按顺序将目标传递给 make
,例如 make value1 value2
,则只需更改逗号,
TARGET
的值转换为空格
.您未提供操作系统,因此我假设使用* nix.您可以使用以下命令快速完成 $ {TARGET//,/}
If you could pass targets to make
in sequence, like make value1 value2
, all you would need is to change that comma ,
in value of TARGET
to a space . You didn't provide your OS, so I will assume *nix. You can use the following to quickly do that
${TARGET//,/ }
最后,由于 make
似乎不支持多个目标(根据OP),因此我们需要一个循环.
Finally, since make
does not appear to support multiple targets (according to OP), we need a loop.
因此,在您的Jenkins 执行Shell 构建步骤中,输入:
So, in your Jenkins Execute Shell build step, type:
for currentTarget in ${TARGET//,/ }; do
make $currentTarget
done
这等同于:
make value1
make value2
关于事物的顺序:这些值的顺序将始终与作业配置中定义的顺序相同.用户选择这些顺序无关紧要.
As for the order of thing: the order of these values will always be same as they are defined in job configuration. It doesn't matter in what order the user chooses these.
这篇关于具有多个值的单个参数-引用扩展选择的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!