Forum Discussion
You can try
1. currentBuild.rawBuild.log (this might be deprecated but let's try)
2. global variable manager using manager.logContains(text) (never tried that )
Anyway, the best way is using Jenkins API methods in your scripts as you may need various methods in the future.
Bonibom, So, even after I fix the permission issue, how do I use the email functionality that was in the post method of the pipeline script.
- Bonibom3 years agoContributor
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.
- tvklovesu3 years agoFrequent Contributor
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")
}
}
}
}