简体   繁体   English

如何在 Jenkins 文件中传递多选值参数(Groovy)

[英]How to pass multi select value parameter in Jenkins file(Groovy)

Eg Below code is used for single select value例如下面的代码用于单个选择值

        choice{
           choices: 'Box\nOneDrive\nSharePointOnline\nGmail\nGDrive\nGenericS3',
           defaultValue: 'box', 
           description:  'Connector to build',
           name: 'On_Cloud_Devices_To_Test'
         }

I would use booleanParam's.我会使用 booleanParam 的。 Then the user can tick all the required options.然后用户可以勾选所有必需的选项。

booleanParam(defaultValue: false, name: 'ALL', description: 'Process all'),
booleanParam(defaultValue: false, name: 'OPTION_1', description: 'Process option 1'),
booleanParam(defaultValue: false, name: 'OPTION_2', description: 'Process options 2'),

You could use "Extended Choice Parameter" plugin, as this page suggests.您可以使用“扩展选择参数”插件,正如本页所建议的那样。

Sinse the parameter list is very long, you may wrap it into a function:由于参数列表很长,你可以把它包装成一个函数:

import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition

def checkBox (String name, String values, String defaultValue,
              int visibleItemCnt=0, String description='', String delimiter=',') {

    // default same as number of values
    visibleItemCnt = visibleItemCnt ?: values.split(',').size()
    return new ExtendedChoiceParameterDefinition(
            name, //name,
            "PT_CHECKBOX", //type
            values, //value
            "", //projectName
            "", //propertyFile
            "", //groovyScript
            "", //groovyScriptFile
            "", //bindings
            "", //groovyClasspath
            "", //propertyKey
            defaultValue, //defaultValue
            "", //defaultPropertyFile
            "", //defaultGroovyScript
            "", //defaultGroovyScriptFile
            "", //defaultBindings
            "", //defaultGroovyClasspath
            "", //defaultPropertyKey
            "", //descriptionPropertyValue
            "", //descriptionPropertyFile
            "", //descriptionGroovyScript
            "", //descriptionGroovyScriptFile
            "", //descriptionBindings
            "", //descriptionGroovyClasspath
            "", //descriptionPropertyKey
            "", //javascriptFile
            "", //javascript
            false, //saveJSONParameterToFile
            false, //quoteValue
            visibleItemCnt, //visibleItemCount
            description, //description
            delimiter //multiSelectDelimiter
            )
}

Then use it as follows:然后按如下方式使用它:

def testParam = checkBox("opt", // name
                "opt1,opt2,opt3", // values
                "opt1", //default value
                0, //visible item cnt
                "Multi-select", // description
                )

properties(
  [parameters([testParam])]
)

node {
    echo "${params.opt}"
}

Jenkins Build with Parameters: Jenkins 使用参数构建:

在此处输入图片说明

This is scripted pipeline syntax by the way.顺便说一下,这是脚本化的管道语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM