Without if statement
In the example below, we have a shell script task with a variable ‘checkStatus’. The value of ‘checkStatus’ will be either ‘on’ when checked, or ‘off’ when unchecked.
checkStatus="<%= customOptions.cluster_checkbox %>"
echo "myVal = $checkStatus"
Using if statement
But on the following task we are using an if statement to set the value of ‘checkStatus’. In this case when the checkbox is checked the value will be ‘on’. But if the checkbox is unchecked the value will not be empty string or ‘off’, but ‘null’.
checkStatus="<%= if (customOptions.cluster_checkbox == 'on') { 'on' } %>"
echo "checkStatus = $checkStatus"
When using if statement as shown above, you must specify the value to return when the checkbox is unchecked. Otherwise, it will just return null. On the example below we are also including an ‘else’ statement to return ‘off’ when unchecked.
checkStatus="<%= if (customOptions.cluster_checkbox == 'on') { 'on' } else { 'off' }%>"
echo "checkStatus = $checkStatus"