Issue
I have a string parameter in my Jenkinsfile which contains a space
parameters { string(name: 'KW_Issue_resolution', defaultValue: 'Not a Problem', description: 'Marking the issue as Not a problem') }
I am trying to pass this parameter into a shell script within a stage
stage ('Mark KW issues as not a problem') {
steps {
sh "kwcheck set-status ${params.KW_Issue_IDs} --status ${params.KW_Issue_resolution}"
}
}
However, the shell doesn't recognize the entire string as "Not a Problem"
+ kwcheck set-status 190 --status Not a Problem
Cannot change status, 'Not' is not a valid status name
Expected the shell command to be kwcheck set-status 190 --status "Not a Problem"
Solution
Since the variable is interpolated in the Groovy interpreter with whitespace, the shell interpreter within the sh
step method will not resolve it as a single argument string due to the delimiter. You can cast it as a literal string in the shell interpreter with the normal syntax:
sh "kwcheck set-status ${params.KW_Issue_IDs} --status '${params.KW_Issue_resolution}'"
Answered By - Matt Schuchard Answer Checked By - Willingham (WPSolving Volunteer)