Created
November 22, 2017 18:16
-
-
Save idletekz/a32298fc22861527482dac91a03175e4 to your computer and use it in GitHub Desktop.
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
Check to see if a build is running or not | |
I tried the Python script in the answer to this question, but couldn't get it to work. I don't know Python, and didn't want to invest any time in debugging, but was able to read enough of the script to gain inspiration from it. | |
All I need to do is check to see if a build is running or not. To do that I used curl and grep, like this: | |
curl http://myjenkins/job/myjob/lastBuild/api/json | grep --color result\":null | |
If a build is in progress, a grep for result\":null will return 0. | |
If a build is finished, a grep for result\":null will return 1. | |
Not especially elegant, but it works well enough for my needs. | |
For example, I have a Bash script that starts a build, then waits for it to finish: | |
JOB_URL=http://jenkins.local/job/stevehhhbuild | |
JOB_STATUS_URL=${JOB_URL}/lastBuild/api/json | |
GREP_RETURN_CODE=0 | |
# Start the build | |
curl $JOB_URL/build?delay=0sec | |
# Poll every thirty seconds until the build is finished | |
while [ $GREP_RETURN_CODE -eq 0 ] | |
do | |
sleep 30 | |
# Grep will return 0 while the build is running: | |
curl --silent $JOB_STATUS_URL | grep result\":null > /dev/null | |
GREP_RETURN_CODE=$? | |
done | |
echo Build finished | |
Thanks for the inspiration, Catskul! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://serverfault.com/questions/309848/how-to-check-the-build-status-of-a-jenkins-build-from-the-command-line?newreg=17eb507a167f4d94bac7f9684e1c4298