Jenkins Choice parameter Passing to a pipeline Job

前端 未结 5 503
粉色の甜心
粉色の甜心 2020-12-30 03:00

Currently I have a pipeline job which has different paramters where one of this parameters is a Choice parameter. Here is the config.xml output of that job parameter:

<
5条回答
  •  醉酒成梦
    2020-12-30 03:35

    In script mode you can also do it like this, at the moment it is bugged and it expects the choice parameters as a newline delimited string instead of an array. When using the Pipeline and JenkinsFile in script mode you can do a quick fix like follows:

    properties(
        [parameters([choice(choices: ["A", "B", "C"].join("\n"),
        description: 'Some choice parameter', 
        name: 'SOME_CHOICE')])])
    

    You can put this before your first node statement to add parameters to your builds.

    Update: example multi select with extended choice parameter plugin in Jenkins pipeline file:

    com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition extendedChoiceParameterDefinition = new com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition(
        "OPTION_NAME", // name
        "PT_CHECKBOX", // type
        "option1,option2,option3", // values
        null, // projectName
        null, // propertyFile
        null, // groovyScript
        null, // groovyScriptFile
        null, // bindings
        null, // groovyClasspath
        null, // propertyKey
        "option1,option2", // defaultValue
        null, // defaultPropertyFile
        null, // defaultGroovyScript
        null, // defaultGroovyScriptFile
        null, // defaultBindings
        null, // defaultGroovyClasspath
        null, // defaultPropertyKey
        null, // descriptionPropertyValue
        null, // descriptionPropertyFile
        null, // descriptionGroovyScript
        null, // descriptionGroovyScriptFile
        null, // descriptionBindings
        null, // descriptionGroovyClasspath
        null, // descriptionPropertyKey
        null, // javascriptFile
        null, // javascript
        false, // saveJSONParameterToFile
        false, // quoteValue
        10, // visible item count
        "Select your options", // description
        "," //multiSelectDelimiter
    )
    
    normalChoiceOptions = ["option1","option2"]
    
    properties([
            parameters([
                    choice(choices: normalChoiceOptions.join("\n"), description: 'Single select option', name: 'SOME_OPTION'),                
                    extendedChoiceParameterDefinition
            ])
    ])
    

提交回复
热议问题