Jenkinsfile中的动态参数? [英] Dynamic Parameter in Jenkinsfile?
问题描述
如何在Jenkinsfile
中使用 Jenkins动态插件?
我正在寻找的是一个Jenkinsfile代码段,
What I am looking for is a Jenkinsfile snippet that:
- 在Jenkins作业中启用
Build with Parameters
选项 - 选中后,将填充一个脚本,该脚本填充可以使用的列表
Dynamic Choice 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编辑器中的
-
Pipeline syntax
- 选择
properties: Set job properties
作为Sample step
- 选择
This project is parameterized
- 使用
Dynamic Choice Parameter
- 输入
Name
,Choice Script
,Remote Script
等的值 -
Generate Pipeline 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?
詹金斯版本: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'){
...
请注意,如果您使用choice参数,则必须提供一个字符串,其中的值用新行分隔.
If you use the choice parameter be aware the you must provide a string where the values are separated by a new line.
例如:
"a\nb\nc"
如果您确实需要插件,请对该问题进行投票 JENKINS-42149 .
If you really need to plugin, then vote on this issue JENKINS-42149.
这篇关于Jenkinsfile中的动态参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!