我有这个模板:
def call(body) {
def pipelineParams= [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
pipeline {
agent any
....
stages {
stage('My stages') {
steps {
script {
pipelineParams.stagesParams.each { k, v ->
if (k.toLowerCase().startsWith("If ") && (params[ k.split(' ')[1] ] as boolean)) {
stage("$k") {
$v
}
}
}
}
}
}
}
post { ... }
}
}
以及使用此模板的相对管道:
@Library('pipeline-library') _
pipelineMyTemplate {
parameters {
booleanParam(name: 'foo', defaultValue: true, description: 'some option')
booleanParam(name: 'bar', defaultValue: true, description: 'some option')
}
stagesParams = [
'If foo run': echo "foo is selected",
'If bar run': echo "bar is selected"
]
}
在我编写if (some option selected in the parameters)
的管道中,如果还没有的话我该如何引用这些参数?另外我还注意到,以这种方式创建时,这些选项未在UI中显示为复选框。
def call(body) {
def pipelineParams= [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
pipeline {
agent any
....
stages {
script {
pipelineParams.stagesParams.each { k, v ->
if (k.toLowerCase().startsWith("If ") && (params[ k.split(' ')[1] ] as boolean)) {
stage("$k") {
sh "$v"
}
}
}
}
}
post { ... }
}}