{"id":2052,"date":"2017-12-07T09:25:48","date_gmt":"2017-12-07T09:25:48","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2052"},"modified":"2020-01-09T09:44:39","modified_gmt":"2020-01-09T09:44:39","slug":"check-to-see-if-a-build-is-running-or-not","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/check-to-see-if-a-build-is-running-or-not\/","title":{"rendered":"Check to see if a build is running or not"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Check to see if a build is running or not<\/strong><br \/>\nAll 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:<\/p>\n<p>curl http:\/\/myjenkins\/job\/myjob\/lastBuild\/api\/json | grep &#8211;color result\\&#8221;:null<\/p>\n<p>If a build is in progress, a grep for result\\&#8221;:null will return 0.<br \/>\nIf a build is finished, a grep for result\\&#8221;:null will return 1.<br \/>\nNot especially elegant, but it works well enough for my needs.<\/p>\n<p>For example, I have a Bash script that starts a build, then waits for it to finish:<\/p>\n<p><code>JOB_URL=http:\/\/jenkins.local\/job\/stevehhhbuild<br \/>\nJOB_STATUS_URL=${JOB_URL}\/lastBuild\/api\/json<\/code><\/p>\n<p>GREP_RETURN_CODE=0<\/p>\n<p># Start the build<br \/>\ncurl $JOB_URL\/build?delay=0sec<\/p>\n<p># Poll every thirty seconds until the build is finished<br \/>\nwhile [ $GREP_RETURN_CODE -eq 0 ]<br \/>\ndo<br \/>\nsleep 30<br \/>\n# Grep will return 0 while the build is running:<br \/>\ncurl &#8211;silent $JOB_STATUS_URL | grep result\\&#8221;:null &gt; \/dev\/null<br \/>\nGREP_RETURN_CODE=$?<br \/>\ndone<\/p>\n<p>echo Build finished<\/p>\n<p>Reference &#8211; <a href=\"http:\/\/serverfault.com\/questions\/309848\/how-can...49988bb53ee820fe202a\" target=\"_blank\" rel=\"noopener\">serverfault.com\/questions\/309848\/how-can&#8230;49988bb53ee820fe202a<\/a><br \/>\nRegards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: Check to see if a build is running or not All I need to do is check to see if a build is running or not&#8230;. <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[42],"tags":[438],"class_list":["post-2052","post","type-post","status-publish","format-standard","hentry","category-jenkins","tag-check"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2052"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2052\/revisions"}],"predecessor-version":[{"id":5336,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2052\/revisions\/5336"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}