Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # The URL of the Jenkins server
- JENKINS_URL=localhost:8080
- # The Jenkins user
- USERNAME=admin
- # The password for the user
- PASSWORD=<password>
- # The job to test
- JOB=test_job
- # The remote trigger token for this job
- TOKEN=myToken
- # A value to determine if the job is currently executing
- JOB_BUILDING=0
- echo " Testing $JOB..."
- # Trigger the job to build remotely
- curl -s $USERNAME:$PASSWORD@$JENKINS_URL/job/$JOB/build?token=$TOKEN
- echo " ...triggered $JOB to build... "
- # ...while the job is still building...
- while [ $JOB_BUILDING -eq 0 ]
- do
- # Give the job time to build, check every 10 seconds
- echo " ...waiting 10 seconds for $JOB to build... "
- sleep 10
- CURL=$(curl -s $USERNAME:$PASSWORD@$JENKINS_URL/job/$JOB/lastBuild/api/json)
- # Only update the JOB_BUILDING variable if the curl succeeds.
- if [ $? -eq 0 ]
- then
- # Grep will return 0 if building: true
- echo $CURL | grep building\":true > /dev/null
- JOB_BUILDING=$?
- fi
- # If the curl command errored, or if still building, sleep and try again
- done
- # Limit output to the result
- RESULT=$(echo $CURL | grep -E -o "result\":.{0,10}" | awk -F'"' '{print $3}')
- # Output the result
- echo " ...$JOB completed! Build Status: $RESULT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement