I am trying to have the reason as it is printed on the console of my Jenkins instance why a build failed through email. I did the following
node {
try
{
stage('checkout') {
checkout scm
}
stage('restore') {
sh 'dotnetge restore test.sln'
}
}
catch (err) {
cause=err
emailext body:"Error: $cause ",
to: 'myemail@gmail.com'
}
}
The result on the console is something like "dotnetge command not found" and i will like to have this same type of error through email. This is what i get through email
Error: hudson.AbortException: script returned exit code 127
Since the shell script failed, it will give the exception you are currently getting. You can have a workaround to handle this:
node {
try
{
stage('checkout') {
checkout scm
}
stage('restore') {
try{
sh 'dotnetge restore test.sln'}
catch(exc){
error "dotnetge command failed"
}
}
}
catch (err) {
cause=err
emailext body:"Error: $cause ",
to: 'myemail@gmail.com'
}
}
This way you can at least know which command failed. What else I did was that I created another variable called curr_stage
and assigned its value to the current stage:
node{
def curr_stage
try {
stage("stage1") {
curr_stage = "stage1"
}
stage("stage2") {
curr_stage = "stage2"
}
stage("stage3") {
curr_stage = "stage3"
}
}catch(exception){
//notify that the the build failed at ${curr_stage}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.