Jenkinsfile 中的动态参数? [英] Dynamic Parameter in Jenkinsfile?

查看:39
本文介绍了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.

尝试时:

  1. 管道语法在 Jenkins 编辑器中
  2. 选择 properties: Set job properties as Sample step
  3. 选择此项目已参数化
  4. 使用动态选择参数
  5. NameChoice ScriptRemote Script 等输入值
  6. 生成管道脚本
  1. Pipeline syntax in the Jenkins editor
  2. Selecting properties: Set job properties as Sample step
  3. Selecting This project is parameterized
  4. Using Dynamic Choice Parameter
  5. Enter values for Name, Choice Script, Remote Script etc
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆