From bf4cc41b3da1e49b915e1a752dd5d14a65ad79e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 26 Apr 2018 16:39:31 +0200 Subject: [PATCH] Add a script to check Jenkins plugins updates --- README.md | 13 +++++++++++++ jenkins_check_update | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 jenkins_check_update diff --git a/README.md b/README.md index 96fbec6..601d86b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ * [Fiber Channel](#fiber_channel) * [Grav](#grav) * [Sesame2mail](#sesame2mail) + * [Jenkins](#jenkins) * [WordPress](#wordpress) @@ -79,6 +80,18 @@ The first argument can be : * A file with a list of user ID (sesame), one per line. * A user ID (sesame), only one. +### Jenkins + +#### jenkins_check_update + +A daily cron to check [Jenkins][jenkins website]'s plugins updates. + * It need [jenkins-cli.jar][jenkins cli]. + * If an update is available, it will create an empty file (${JENKINS_HOME}/.update_plugin), else it will ensure the "update" file is absent. + * Be sure to monitore if this file **${JENKINS_HOME}/.update_plugin** exist ! + +[jenkins website]: https://jenkins.io/ +[jenkins cli]: https://jenkins.io/doc/book/managing/cli/#downloading-the-client + ### WordPress #### wordpress_cron diff --git a/jenkins_check_update b/jenkins_check_update new file mode 100755 index 0000000..6dc0430 --- /dev/null +++ b/jenkins_check_update @@ -0,0 +1,39 @@ +#!/bin/sh + +# This script do the following : +# Use jenkins-cli.jar +# Verify if an update is available for Jenkins plugins. +# Create a file you need to monitore. +# +# How-to use it ? +# Run it with `jenkins_check_update +# Add a symlink to /etc/cron.daily +# ln -s $(pwd)/jenkins_check_update /etc/cron.daily/ + +JENKINS_HOME="/var/lib/jenkins" +JENKINS_CLI_JAR="${JENKINS_HOME}/war/WEB-INF/jenkins-cli.jar" +JENKINS_AUTH_FILE="/root/.jenkins.auth" + +JENKINS_PLUGIN_UPDATE_LOG="${JENKINS_HOME}/.update_plugin" + +if [ ! -f "${JENKINS_CLI_JAR}" ]; then + printf '%b\n' "Jenkins-cli (${JENKINS_CLI_JAR}) does not seem to be available." + exit 1 +fi + +if [ ! -f "${JENKINS_AUTH_FILE}" ]; then + printf '%b\n' "Jenkins authentication file (${JENKINS_AUTH_FILE}) does not seem to be available." + exit 1 +fi + +# Verify if updates are availables for plugins +if java -jar "${JENKINS_CLI_JAR}" -s http://127.0.0.1:8080 -auth @.jenkins.auth list-plugins | grep -i -q -- "(.*)$" +then + touch "${JENKINS_PLUGIN_UPDATE_LOG}" + #printf '%b\n' "Please upgrade plugins" +else + rm -f "${JENKINS_PLUGIN_UPDATE_LOG}" + #printf '%b\n' "Nothing to do" +fi + +exit 0