Forked from markjlorenz/jenkins-api-start-and-monitor-a-build
Created
July 24, 2020 23:56
-
-
Save luaysuarna/3f84e7359ab67436ae2a6e77dd735fab 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