Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # The URL of the Jenkins server
  4. JENKINS_URL=localhost:8080
  5. # The Jenkins user
  6. USERNAME=admin
  7. # The password for the user
  8. PASSWORD=<password>
  9.  
  10. # The job to test
  11. JOB=test_job
  12. # The remote trigger token for this job
  13. TOKEN=myToken
  14.  
  15. # A value to determine if the job is currently executing
  16. JOB_BUILDING=0
  17.  
  18. echo " Testing $JOB..."
  19.  
  20. # Trigger the job to build remotely
  21. curl -s $USERNAME:$PASSWORD@$JENKINS_URL/job/$JOB/build?token=$TOKEN
  22. echo " ...triggered $JOB to build... "
  23.  
  24. # ...while the job is still building...
  25. while [ $JOB_BUILDING -eq 0 ]
  26. do
  27. # Give the job time to build, check every 10 seconds
  28. echo " ...waiting 10 seconds for $JOB to build... "
  29. sleep 10
  30. CURL=$(curl -s $USERNAME:$PASSWORD@$JENKINS_URL/job/$JOB/lastBuild/api/json)
  31. # Only update the JOB_BUILDING variable if the curl succeeds.
  32. if [ $? -eq 0 ]
  33. then
  34. # Grep will return 0 if building: true
  35. echo $CURL | grep building\":true > /dev/null
  36. JOB_BUILDING=$?
  37. fi
  38. # If the curl command errored, or if still building, sleep and try again
  39. done
  40.  
  41. # Limit output to the result
  42. RESULT=$(echo $CURL | grep -E -o "result\":.{0,10}" | awk -F'"' '{print $3}')
  43.  
  44. # Output the result
  45. echo " ...$JOB completed! Build Status: $RESULT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement