Skip to content

Instantly share code, notes, and snippets.

@saquibtmf
Forked from paul-butcher/checkjobs.groovy
Created January 13, 2023 10:19
Show Gist options
  • Save saquibtmf/c7a6e32d642b1975a8e3f6c0470b017e to your computer and use it in GitHub Desktop.
Save saquibtmf/c7a6e32d642b1975a8e3f6c0470b017e to your computer and use it in GitHub Desktop.
Jenkins pipeline to check the status of a set of other jobs
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