-
Type:
Task
-
Resolution: Fixed
-
Priority:
Minor
-
Component/s: active-choices-plugin
I want a the choice option values be populated at runtime by a function.
The following code should to generate a list of options, but for some reason its not working ...Â
def getEnv() {
return["Dev","Prod"]
}
def getServerByEnvParam(env_param) {
if (env_param.equals("Dev")){
return["dev01","dev02"]
}
else if(env_param.equals("Prod")){
return["prd001","prd02"]
} else {
return["unknown"]
}
}
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select Environment',
name: 'myEnv',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'myEnv Error\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return getEnv()'
]
]
],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select Server',
filterable: false,
name: 'myServer',
referencedParameters: 'myEnv',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'myServer Error\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return getServerByEnvParam(myEnv)'
]
]
]
])
])
pipeline {
agent any stages {
stage('Init') {
steps {
script{
println getServerByEnvParam(myEnv)
}
}
}
}
}
Â
how can I to define and use these functions inside jenkins file?Â
is a pipeline supports dynamic parameters based on function in shared libraries?Â
- duplicates
-
JENKINS-63284 Add support to Pipeline API
-
- Open
-