aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_jenkins_job
blob: caab6a70eea6b4349172847358195507bff09fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

# Usage: check_jenkins_job <jenkins-url> <view> <job> <curl opts ...>

if [ "$#" -lt 3 ]; then
	echo "Usage: $0 <jenkins-url> <view> <job> <curl opts ...>"
	exit 3
fi

JENKINS_URL=$1
VIEW=$2
JOB=$3
PASS=$5
USER=$4

shift 5

CURL_OUT=$( curl -s --basic -u "$USER:$PASS" "$@" "$JENKINS_URL/view/$VIEW/job/$JOB/lastBuild/api/json" )

RESULT=$( jq -r .result <<< "$CURL_OUT" )
RUNNING=$( jq -r .building <<< "$CURL_OUT" )
ID=$( jq -r .displayName <<< "$CURL_OUT" )

if [ "$RESULT" = "SUCCESS" ]; then
	echo "JOB OK: $JOB $ID succeeded"
	exit 0
elif [ "$RUNNING" = "true" ]; then
	echo "JOB OK: $JOB $ID is running"
	exit 0
fi

echo "JOB CRITICAL: $JOB $ID failed"
exit 2