[Fuego] [PATCH 8/9] Refactor plugin installation script

Guilherme Campos Camargo guicc at profusion.mobi
Fri Jan 26 17:35:44 UTC 2018


On this patch we're trying to remove the explicit sleeps from the plugin
installation script, that are necessary for waiting for Jenkins
start/restart and the installation of the plugins.

With this change we hope that faster hosts (or hosts with faster
networks) will be able to finish Jenkins plugins installation sooner.

We also took the chance to remove the call to sudo, that are not
necessary for using jenkins-cli.

Signed-off-by: Guilherme Campos Camargo <guicc at profusion.mobi>
---
 frontend-install/setup/jenkins/plugins/install.sh | 44 +++++++++++++++++------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/frontend-install/setup/jenkins/plugins/install.sh b/frontend-install/setup/jenkins/plugins/install.sh
index 0db8bf2..37e8948 100755
--- a/frontend-install/setup/jenkins/plugins/install.sh
+++ b/frontend-install/setup/jenkins/plugins/install.sh
@@ -2,20 +2,42 @@
 
 set -e
 
+function install_jenkins_plugin {
+    echo "Waiting for Jenkins update center..."
+    while ! ret=$(java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/fuego install-plugin "$1" 2>/dev/null); do
+        sleep "$2"
+    done
+    echo "${ret}"
+}
+
+function wait_for_jenkins {
+    echo "Waiting for Jenkins..."
+    while ! curl --output /dev/null --silent --head --fail http://localhost:8080/fuego/ ; do
+        sleep "$1"
+    done
+}
+
+readonly sleep_time_s=1
+readonly required_plugins="
+   description-setter
+   pegdown-formatter
+   flot-plotter-plugin/flot.hpi
+   "
+
 service jenkins start
-sleep 30
-sudo -u jenkins java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/fuego install-plugin description-setter
-sudo -u jenkins java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/fuego install-plugin pegdown-formatter
-sudo -u jenkins java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/fuego install-plugin flot-plotter-plugin/flot.hpi
-sleep 10
+wait_for_jenkins ${sleep_time_s}
+
+for plugin in ${required_plugins}; do
+    install_jenkins_plugin "${plugin}" "${sleep_time_s}"
+done
 
 # Let Jenkins install flot before making the symlink
 service jenkins restart
-sleep 30
-rm $JENKINS_HOME/plugins/flot/flot/mod.js
-ln -s /fuego-core/engine/scripts/mod.js $JENKINS_HOME/plugins/flot/flot/mod.js
-ln -s /fuego-rw/logs $JENKINS_HOME/userContent/fuego.logs
-ln -s /fuego-core/engine/scripts/ftc /usr/local/bin/
+wait_for_jenkins 1
 
-chown -R jenkins:jenkins $JENKINS_HOME/
+rm "$JENKINS_HOME/plugins/flot/flot/mod.js"
+ln -s /fuego-core/engine/scripts/mod.js "$JENKINS_HOME/plugins/flot/flot/mod.js"
+ln -s /fuego-rw/logs "$JENKINS_HOME/userContent/fuego.logs"
+ln -s /fuego-core/engine/scripts/ftc /usr/local/bin/
 
+chown -R jenkins:jenkins "$JENKINS_HOME/"
-- 
2.15.1



More information about the Fuego mailing list