Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save markjlorenz/12f9e7f9befb7ce7998284f73b4b5b4f to your computer and use it in GitHub Desktop.
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
#! /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