Reputation: 65
I need to execute shell script if build is success and execute other script if it fails, is there any plugin or shell script to get build success/failure? Thanks in advance
Upvotes: 3
Views: 4791
Reputation: 151
no plugins necessary use the jenkins post
block after your stages
block
post {
always {
echo "I'm always ran"
}
success {
echo "All builds completed OK"
}
failure {
echo "A job failed"
}
}
documentation on this can be found here: https://www.jenkins.io/doc/book/pipeline/syntax/#post
Upvotes: 0
Reputation: 8257
You can write a Groovy pipiline with this structure:
node {
//Define your variables (if you need)
stage('First stage') {
try {
//Your code
} catch (Exception err) {
currentBuild.result = 'FAILURE'
}
}
stage('Last stage') {
try {
//Your code
} catch (Exception err) {
currentBuild.result = 'FAILURE'
}
}
echo "RESULT: ${currentBuild.result}"
}
Second, thirty... stages only will be executed if previusly steeps builds correctly.
If all your stages build correctly, the status in Jenkins will be SUCCESS
but if anyone fails the status will be FAILURE
.
Upvotes: 3