Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
@NonCPS
def getLastRelease() {
def RES = sh(script: '''cat version''', returnStdout: true).trim()
return RES
pipeline{
parameters {
choice(name: 'RELEASE_VERSION', choices: '${getLastRelease()}', description: 'desc')
But for some reason it does not work - if i try:
'${getLastRelease()}'
I am getting error:
durable-73075a87/script.sh: line 1: ${getLastRelease()}: bad
substitution
if i use:
"${getLastRelease()}"
I am getting error:
[Pipeline] Start of Pipeline [Pipeline] sh [Pipeline] End of Pipeline
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException:
Required context class hudson.FilePath is missing Perhaps you forgot
to surround the code with a step that provides this, such as: node,
dockerNode
–
–
Remove the annotation @NonCPS
, since NonCPS functions should not use Pipeline steps internally.
Since you execute shell scripts, wrap the expressions in your function in a node {...}
block.
Simply invoke the function getLastRelease()
inside the choice the parameter without the quotes or the curly braces.
Working sample:
def getLastRelease() {
node {
def RES = sh (script: 'cat version', returnStdout: true).trim()
return RES
pipeline {
agent any
parameters {
choice(name: 'RELEASE_VERSION', choices: [getLastRelease(), <more choices, ...>], description: 'desc')
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.