I have a task where if the number of standby more than 1, a prompt to Abort or proceed will show. If the person is okay with the selected standby the user will click proceed and the pipeline will continue, otherwise if the user click Abort, the pipeline should exit. I have seen examples but how to bring the variables from the shell to the pipeline is an issue for me
#!/usr/bin/env groovy
stage('check_var_standby') {
environment{
}
node(master) {
unstash 'db-switchover'
sh """
sudo cat /pathtofile/var_standby.txt
var_standby=`sudo cat /pathtofile/var_standby.txt`
sudo echo "\${var_standby}"
if [[ "\${var_standby}" -eq 1 ]]; then
echo "The stand by is equal to 1"
elif [[ "\${var_standby}" -gt 1 ]]; then
echo "The stand by is more than 1 and there is need to choose the right"
else
echo "There is no standby in the variable and this might not work"
fi
""".stripIndent()
// How to prompt user to consider to proceed or abort with a message if var_standby is more than 1
//If the user select proceed then the pipeline continues, but if the user click Abort then the pipeline will exit or failed without continuing
}
}
CodePudding user response:
There are different ways to achieve what you need. Here is one option. Am assuming var_standby.txt
just have a number. If you have additional data you can process the content.
VAR_STANDBY = sh (script: 'sudo cat /pathtofile/var_standby.txt', returnStdout: true).trim()
if(VAR_STANDBY == "1") {
error "Aborting the Build because VAR_STANDBY is 1"
}
timeout(time: 5, unit: "MINUTES") {
input message: 'Do you want to proceed?', ok: 'Yes'
}