I'm teaching myself Jenkins and am trying to direct execution flow of a 'pipeline job via declarative syntax' based on result of Test Stage, which I try to implement via the pytest exit code into a shell variable (i.e. if success then send success email and deploy, if failure then send failure email and exit script..)
This works for me when I export if I set a new shell variable in the CLI. It also seems to work in this Jenkins script to the point when I receive the pytest exit code and assign it to my shell variable. However after this, when I try to read the shell variable I've just set, it seems to have a null value. Any ideas?
stage('Test') {
steps {
sh 'export pytestExitCode'
sh 'echo "pytestExitCode before being assigned the pytest exit code is: "$pytestExitCode'
sh 'pytest'
sh 'echo "Pytest completed with exit code: "$?'
sh 'pytestExitCode=$?'
sh 'echo $pytestExitCode'
sh 'echo "pytestExitCode after being assigned the pytest exit code is: "$pytestExitCode'
}
}