目前我有一个管道作业,它有不同的参数,其中一个参数是Choice参数。以下是该作业参数的config.xml输出:
<hudson.model.ChoiceParameterDefinition>
<choices class="java.util.Arrays$ArrayList">
<a class="string-array">
<string>f1</string>
<string>f2</string>
<string>f3</string>
<string>f4</string>
</a>
</choices>
<name>WHERE</name>
<description>Something</description>
</hudson.model.ChoiceParameterDefinition>现在,我可以通过传递一个字符串参数从管道via调用此作业:
build job: "NameOfTheJob"", parameters:
[
[$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"],
]但是我不能得到一种方法来定义一个choice参数的参数:
我尝试过以下几种方法:
build job: "NameOfTheJob"", parameters:
[
[$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"],
[$class: 'ChoiceParameterValue', name: 'WHERE', value: 'F3'],
]但此操作失败,并显示以下错误:
java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is named ChoiceParameterValue所以问题是:如何在调用其他流水线作业时定义选择参数:
build job: "NameOfTheJob"", parameters:
[
[$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"],
[$class: '??????', ????],
]有人举过这样的例子吗?
发布于 2017-01-20 17:56:45
我见过一个使用以下语法的工作示例:
build job:'NameOfTheJob', parameters: [
string(name: 'FirstOption', value: "test"),
string(name: 'AnotherOption', value: "test12")
]基本上,不要以特殊的方式对待choice参数,只是将它们当作常规的字符串参数。
发布于 2017-04-11 22:33:44
在脚本模式下,你也可以这样做,在它被you的时候,它希望选择参数是换行符分隔的字符串,而不是数组。在脚本模式下使用管道和JenkinsFile时,可以执行快速修复,如下所示:
properties(
[parameters([choice(choices: ["A", "B", "C"].join("\n"),
description: 'Some choice parameter',
name: 'SOME_CHOICE')])])您可以将其放在第一个node语句之前,以便向构建中添加参数。
更新: Jenkins管道文件中带有扩展选择参数插件的示例多选:
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
])
])发布于 2017-01-20 17:28:35
基于c3st7n的技巧,我测试了以下内容:
build job: "NameOfTheJob"", parameters:
[
[$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"],
[$class: 'StringParameterValue', name: 'WHERE', value: "F3"],
]这是可行的。
https://stackoverflow.com/questions/41759405
复制相似问题