Not that you would, but if you DID add a whole bunch of parameters for your pipeline job... why not have it in version control?
To avoid the obligatory 500 million unsafe script approvals readMyProps
may need to got to workflow-libs
folder
def myText = ''' | |
properties: | |
- param: booleanParam | |
args: | |
name: ENABLE_AAT | |
defaultValue: true | |
description: "Should we run AATs" | |
- param: stringParam | |
args: | |
name: NEXT_BUILD | |
defaultValue: '${env.BUILD_NUMBER.toInteger() + 1}' | |
description: 'Choose the next build number' | |
''' | |
node('master') { | |
stage('yaml') { | |
def myYaml = readYaml text: myText | |
def myProps = readMyProps myYaml.properties | |
properties([ | |
parameters(myProps) | |
]) | |
} | |
} | |
@NonCPS | |
def readMyProps(properties) { | |
properties.collect { parameter -> | |
this.invokeMethod parameter.param, parameter.args.collectEntries { name, value -> | |
[ | |
name, | |
value instanceof String ? interp(value) : value | |
] | |
} | |
} | |
} | |
@NonCPS | |
def interp(value) { | |
new groovy.text.GStringTemplateEngine() | |
.createTemplate(value) | |
.make([env:env]) | |
.toString() | |
} |