Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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