Created
July 23, 2016 18:11
-
-
Save markjlorenz/12f9e7f9befb7ce7998284f73b4b5b4f to your computer and use it in GitHub Desktop.
Start a job with the Jenkins API and monitor it's console output
This file contains 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
#! /usr/bin/env bash | |
JENKINS_URL="localhost:8080" | |
JOB_NAME="YourJobName | |
USER_NAME="api" | |
USER_TOKEN="f6706YOURUSERTOKENd2c51" | |
QUEUE_URL=$(curl --silent "http://${JENKINS_URL}/job/${JOB_NAME}/build" \ | |
--user "${USER_NAME}:${USER_TOKEN}" \ | |
--data "token=${JOB_TOKEN}" -XPOST \ | |
--dump-header - \ | |
--output /dev/null \ | |
| grep Location \ | |
| awk '{print $2}' \ | |
| tr -d '\r\n' | |
) | |
echo "${QUEUE_URL}api/json" | |
BUILD_URL='' | |
while [ ! -n "$BUILD_URL" ]; do | |
BUILD_URL=$( | |
curl --silent "${QUEUE_URL}api/json" \ | |
--user "${USER_NAME}:${USER_TOKEN}" \ | |
| jq -r '.executable.url' | |
) | |
sleep 1 | |
done | |
echo $BUILD_URL | |
curl --silent "$BUILD_URL/consoleText" \ | |
--user "${USER_NAME}:${USER_TOKEN}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment