Forum Discussion
You can modify variables in the condition block (where you check exit code contains -1) and use those variables in the body, subject in the emailext or everywhere you need in the pipeline. If you meant that. But this does not relate to topic the current thread and more relate to general programming.
Thanks for your help. Finally, I am able to read the exit code and send the emails only when the exit code is -1. Here is my script for anyone else need it later.
stage('Checking log'){
steps{
script{
//List<String> log= currentBuild.rawBuild.getLog(100)
boolean Pass= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 0.")
boolean Fail= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 2.")
boolean error= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 3.")
boolean license= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: -1.")
if (Pass)
{
echo 'Passed'
}else if (Fail){
echo "Failed."
emailext (
subject: "Core application Failed to login in Prod",
body: "Core application seems to be failed to login in Prod. Please click the link to access the test results for more details \n" + env.BUILD_URL+"TestComplete/",
to: 'xyz@xxx.com, abc@xxx.com, 123@xxx.com'
from: "donotreply@cloudbees.com")
}
else if (error || license){
echo "Error or License"
emailext (
subject: "TestComplete has error to run in jenkins",
body: "TestComplete failed to run in Jenkins. Please click the link to access the test results for more details \n" + env.BUILD_URL+"TestComplete/",
to: 'xyz@xxx.com'
from: "donotreply@cloudbees.com")
}
}
}
}