Jenkinsfile 中的动态参数? [英] Dynamic Parameter in Jenkinsfile?
问题描述
如何在 Jenkinsfile
中使用 Jenkins 动态插件?
我正在寻找的是一个 Jenkinsfile 片段:
What I am looking for is a Jenkinsfile snippet that:
- 在 Jenkins 作业中启用
Build with Parameters
选项 - 选中后,将填充一个可用于
动态选择参数
的列表的脚本,并且用户将看到一个下拉列表.
- Enables the
Build with Parameters
option in the Jenkins job - When selected, a script that populates a list that can be used
Dynamic Choice Parameters
is populated and the user will see a drop down list.
尝试时:
管道语法
在 Jenkins 编辑器中- 选择
properties: Set job properties
asSample step
- 选择
此项目已参数化
- 使用
动态选择参数
- 为
Name
、Choice Script
、Remote Script
等输入值 生成管道脚本
Pipeline syntax
in the Jenkins editor- Selecting
properties: Set job properties
asSample step
- Selecting
This project is parameterized
- Using
Dynamic Choice Parameter
- Enter values for
Name
,Choice Script
,Remote Script
etc Generate Pipeline Script
我得到以下模板:
properties([
parameters([
<object of type com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition>
]),
pipelineTriggers([])
])
即生成的管道脚本不包含我在上面的步骤 5.
中输入的数据.如何修改 parameters
以便用户可以看到参数名称、选项等?
i.e. the generated pipeline script does not contain the data that I have entered in step 5.
above. How can I modify parameters
so that parameter name, choices, etc will be visible to the user?
Jenkins 版本:2.19.3动态参数插件版本:0.2.0
Jenkins version: 2.19.3 Dynamic Parameter Plugin version: 0.2.0
推荐答案
不再需要 Jenkins 动态插件.只需使用正常的选择或字符串参数,并通过 groovy 代码更新值.
there is no need anymore for the Jenkins Dynamic Plugin anymore. Just use the normal choice or string parameter and have the value(s) updated by groovy code.
#!/bin/groovy
def envs = loadEnvs();
properties([
parameters([
choice(choices: envs, description: 'Please select an environment', name: 'Env')
])
])
node {
try {
stage('Preparation'){
...
如果您使用选择参数,请注意,您必须提供一个字符串,其中值由新行分隔.
If you use the choice parameter be aware the you must provide a string where the values are separated by a new line.
例如:
"a
b
c"
如果你真的需要插件,那就在这个问题上投票 JENKINS-42149.
If you really need to plugin, then vote on this issue JENKINS-42149.
这篇关于Jenkinsfile 中的动态参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!