Skip to content

Instantly share code, notes, and snippets.

@mika
Created September 3, 2019 11:35
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 mika/a08cb109a601bea9e943aab9ada9691b to your computer and use it in GitHub Desktop.
Save mika/a08cb109a601bea9e943aab9ada9691b to your computer and use it in GitHub Desktop.
modules/profile/files/monitoring/local/check_jenkins_plugins
#!/bin/bash
# HEADER: managed by puppet, do NOT edit manually!
set -u
if [ ! -e /lib/systemd/system/jenkins.service ] ; then
# Check should be enabled only on jenkins master hosts
exit 0
fi
script=$(basename "$(readlink -f "$0")")
if pgrep -f list-plugins >/dev/null; then
result="Check is already running"
rc=1
else
cli=/var/lib/jenkins/jenkins-cli.jar
# shellcheck disable=SC2016
awk_script='BEGIN {ORS=", "} { if ( $NF ~ /^\(/ ) print $1}'
updates=$(java -jar ${cli} -ssh -user jenkins -i /var/lib/jenkins/.ssh/id_rsa_jenkins -s http://localhost:8080 list-plugins | awk "${awk_script}")
if [ -n "${updates:-}" ] ; then
num=$(echo "${updates}" | wc -w)
result="Plugin updates (${num}): ${updates}"
rc=1
else
result="No plugin updates"
rc=0
fi
fi
echo "${rc:-2} ${script} - ${result:-UNKNOWN ERROR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment