Created
November 3, 2016 09:35
-
-
Save paul-butcher/dc68adc1c05ca970158c18206756dab1 to your computer and use it in GitHub Desktop.
Jenkins pipeline to check the status of a set of other jobs
This file contains hidden or 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
After changing 'jobName' in line 12, script fails to run complaining of 'httpRequest' in line 4.
Removed that too and now rx.getContent() seems to be invalid. Error is:
No signature of method: java.lang.String.getContent() is applicable for argument types: () values: []
Possible solutions: getBytes()
Want to know if you were able to get job status with this code snippet ?