Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abderrazak-bouadma/d1f1a790ba99420714534e10948d8bab to your computer and use it in GitHub Desktop.
Save abderrazak-bouadma/d1f1a790ba99420714534e10948d8bab 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