-
-
Save saquibtmf/c7a6e32d642b1975a8e3f6c0470b017e to your computer and use it in GitHub Desktop.
Jenkins pipeline to check the status of a set of other jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def getJobStatus(String jobName){ | |
def rx = httpRequest "https://jenkins.example.com/job/${jobName}/lastBuild/api/json" | |
def rxJson = new JsonSlurper().parseText(rx.getContent()) | |
return rxJson['result'] | |
} | |
node() { | |
def any_success = false | |
stage('check'){ | |
for(jobname in ['SomeJob', 'AnotherJob']){ | |
jobStatus = getJobStatus(jobName) | |
echo jobStatus | |
if(jobStatus == "SUCCESS" || jobStatus == "UNSTABLE"){ | |
any_success = true | |
break | |
} | |
} | |
} | |
stage('report') { | |
if(!any_success){ | |
httpRequest 'https://jenkins.example.com/sounds/playSound?src=https://jenkins.example.com/userContent/sounds/dead.wav' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment