我做了一些研究,但无法将这些类型的参数传递给使用相同参数的第二份工作。我怀疑这是不可能的,因为没有“值”类型可以传递给这个插件参数类。
所以我在这里看到的唯一选择就是在第二个作业中使用字符串参数。我想在第二份工作中你已经对该参数值进行了一些解析,所以你不需要做太多改变:
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_MULTI_SELECT',
filterLength: 1,
filterable: false,
name: 'TEST_PARAM',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: 'return ["Check Jenkins ScriptApproval page"]'
],
script: [
classpath: [],
sandbox: false,
script: 'return ["One","Two:selected"]'
]
]
]
])
])
pipeline {
agent any
stages {
stage('Test') {
steps {
print params.TEST_PARAM
build job: 'test2', parameters: [
string(name: 'TEST_PARAM', value: "${params.TEST_PARAM}")
]
}
}
}
}
然后在第二份工作中(姓名 = test2):
pipeline {
agent any
parameters {
string(name: 'TEST_PARAM', defaultValue: '')
}
stages {
stage('Test') {
steps {
script {
// split values, guess you're doing this already
// since the value of the parameter is also comma-separted
// when you get from "Active choice parameter"
def testParamValues = "${params.TEST_PARAM}".split(',')
testParamValues.each { testParamValue ->
print testParamValue.trim()
}
}
}
}
}
}
如果您想在管道中同时使用“主动选择参数”和该字符串参数,您可以检查哪一个的长度 > 0,然后使用该值。