Reputation: 3606
I have pipeline with input which is correctly echoing i.e. 'Destroy: true' but not in the next echo inside 'sh' script. I tried ${destroyCluster} or $destroyCluster there but no difference , echo shows empty
script {
def destroyCluster = input(
id: 'destroyCluster', message: 'Destroy cluster ?',
parameters: [[$class: 'BooleanParameterDefinition', defaultValue: false, description: 'Destroy cluster', name: 'destroy'],
]
)
echo ("Destroy: "+ destroyCluster)
sh '''
echo "${destroyCluster}"
'''
Upvotes: 1
Views: 313
Reputation: 28874
The problem here is you need to either interpolate the Groovy variable within Groovy if you are passing it to the shell step method for interpretation, or use it as a first class expression within Groovy.
Showing examples for both of these possibilities:
script {
def destroyCluster = input(
id: 'destroyCluster',
message: 'Destroy cluster ?',
parameters: [[$class: 'BooleanParameterDefinition',
defaultValue: false,
description: 'Destroy cluster',
name: 'destroy']])
echo "Destroy: ${destroyCluster}" // proper Groovy interpolation
print destroyCluster // first class expression
If nothing is still output to standard out in the Jenkins Pipeline logs, then destroyCluster
is a void
type method and does not return anything. In that case, you will be unable to assign and utilize its return value.
Upvotes: 1