如何使用脚本化管道方法在参数化构建中定义Label参数 [英] How to define a Label parameter in a parameterized build using scripted pipeline approach
问题描述
I'm trying to solve the same problem as this SO question: How to trigger a jenkins build on specific node using pipeline plugin?
在我的情况下,唯一的区别是我触发的作业是另一个脚本化管道作业.因此,建议的解决方案中的第二步不适用于我的情况:
The only difference in my case is that the job I'm triggering is another scripted pipeline job. So the second step in the proposed solution does not apply in my case:
- 安装节点和标签参数插件
- 在test_job的配置中,选择此构建已参数化"并添加Label参数,并将参数名称设置为"node"
- 在管道脚本中,使用代码(省略代码)
我的问题是如何定义:
org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition
脚本化管道参数化作业中的参数(不是通过GUI).
parameter inside my scripted pipeline parameterized job (not through the GUI).
我尝试过的事情:
properties([[$class : 'RebuildSettings',
autoRebuild : false,
rebuildDisabled: false],
parameters([org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition(name: 'node')])])
推荐答案
生成参数化脚本化管道所需代码的最简单方法是:
The easiest way to generate the code you need for your parameterized scripted pipeline is to:
- 转到管道摘要生成器
- 选择属性:设置作业属性"
- 选中此项目已参数化"
- 点击添加参数",然后选择标签"
- 点击生成管道脚本"
这给您:
properties([
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
parameters([
[$class: 'LabelParameterDefinition',
allNodesMatchingLabel: false,
defaultValue: '',
description: '',
name: 'node',
nodeEligibility: [$class: 'AllNodeEligibility'], t
riggerIfResult: 'allCases']
]
)
])
但是对于我来说,这甚至是没有必要的.您需要做的是一个带有自定义名称的常规字符串参数,让我们说节点",然后执行以下操作:
But in my case this wasn't even necessary. All you need is a regular string parameter with a custom name, lets say "node" and then do:
node(params.node){}
这篇关于如何使用脚本化管道方法在参数化构建中定义Label参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!