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

查看:567
本文介绍了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编辑器中的
  1. Pipeline syntax
  2. 选择properties: Set job properties作为Sample step
  3. 选择This project is parameterized
  4. 使用Dynamic Choice Parameter
  5. 输入NameChoice ScriptRemote Script等的值
  6. Generate Pipeline Script
  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?

詹金斯版本: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屋!

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