Skip to content

Instantly share code, notes, and snippets.

@otsuarez
Created June 11, 2013 18:54
Show Gist options
  • Save otsuarez/5759618 to your computer and use it in GitHub Desktop.
Save otsuarez/5759618 to your computer and use it in GitHub Desktop.
shell script for checking remote jenkins build execution
echo "deploying ${PROJECT}-${VERSION}.zip"
JOB_URL="http://jenkins.devops.com.ar/job/Push_Artifactory"
JOB_STATUS_URL="${JOB_URL}/lastBuild/api/json"
GREP_RETURN_CODE=0
# Start the build
JENKINS_USER=jenkins-frontend
API_TOKEN=c**85ffcc***13abc397
curl --user $JENKINS_USER:$API_TOKEN "$JOB_URL/buildWithParameters?env=${STAGE}&repo=${PROJECT}&revision=${VERSION}"
# Poll every ten seconds until the build is finished
while [ ${GREP_RETURN_CODE} -eq 0 ]
do
sleep 10
JSON_REPONSE=`curl "$JOB_STATUS_URL"`
GREP_RETURN_CODE=$?
if echo ${JSON_REPONSE} | fgrep -q 'result":null'
then
echo "remote jenkins still working .."
else
GREP_RETURN_CODE=1
fi
done
if echo $JSON_REPONSE | fgrep -q 'result":"SUCCESS'
then
echo "SUCCESS!!"
RESPOSE=0
else
echo "FAILED!!"
RESPONSE=1
fi
echo "Build finished"
exit $RESPONSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment