Can the parameters in a Jenkins declarative pipeline be dynamic?
I want a the choice option values be populated at runtime by a function. The following code does gen
For anyone needing a declarative pipeline syntax option, I found a good solution in another question, which helped me.
This is my suggestion based on it. You should be able to generate a more dynamic list with the code that creates the ${WORKSPACE}/list
file
pipeline {
agent any
stages {
stage("Release scope") {
steps {
script {
// Prepare a list and write to file
sh "echo \"patch\nminor\nmajor\" > ${WORKSPACE}/list"
// Load the list into a variable
env.LIST = readFile (file: "${WORKSPACE}/list")
// Show the select input
env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
parameters: [choice(name: 'RELEASE_SCOPE', choices: env.LIST, description: 'What is the release scope?')]
}
echo "Release scope selected: ${env.RELEASE_SCOPE}"
}
}
}
}
I hope this helps