blob: 027c38234a5d2d8789266237abb53d3a0d8fa613 [file] [log] [blame]
Nicolas De Loofacb86492014-10-24 13:43:13 +02001#! /bin/bash
2
3# Parse a support-core plugin -style txt file as specification for jenkins plugins to be installed
4# in the reference directory, so user can define a derived Docker image with just :
Nikolay Yurin390dc612015-04-20 14:46:29 +03005#
Nicolas De Loofacb86492014-10-24 13:43:13 +02006# FROM jenkins
7# COPY plugins.txt /plugins.txt
Justin Clayton8aec15c2015-01-23 12:19:02 -08008# RUN /usr/local/bin/plugins.sh /plugins.txt
Nikolay Yurin390dc612015-04-20 14:46:29 +03009#
Jim Zucker4e24cac2016-04-05 08:06:38 -070010# Note: Plugins already installed are skipped
11#
Nicolas De Loofacb86492014-10-24 13:43:13 +020012
Jesse Glick9c8ddc42015-06-01 11:47:18 -040013set -e
14
Carlos Sanchez0ab40702016-08-05 10:44:58 +020015echo "WARN: plugins.sh is deprecated, please switch to install-plugins.sh"
16
Jim Zucker4e24cac2016-04-05 08:06:38 -070017if [ -z "$1" ]
18then
Carlos Sanchez44deec32016-06-10 12:21:21 +020019 echo "
20USAGE:
Jim Zucker4e24cac2016-04-05 08:06:38 -070021 Parse a support-core plugin -style txt file as specification for jenkins plugins to be installed
22 in the reference directory, so user can define a derived Docker image with just :
Carlos Sanchez44deec32016-06-10 12:21:21 +020023
Jim Zucker4e24cac2016-04-05 08:06:38 -070024 FROM jenkins
25 COPY plugins.txt /plugins.txt
26 RUN /usr/local/bin/plugins.sh /plugins.txt
Carlos Sanchez44deec32016-06-10 12:21:21 +020027
Jim Zucker4e24cac2016-04-05 08:06:38 -070028 Note: Plugins already installed are skipped
Carlos Sanchez44deec32016-06-10 12:21:21 +020029
Jim Zucker4e24cac2016-04-05 08:06:38 -070030"
Carlos Sanchez44deec32016-06-10 12:21:21 +020031 exit 1
Jim Zucker4e24cac2016-04-05 08:06:38 -070032else
Carlos Sanchez44deec32016-06-10 12:21:21 +020033 JENKINS_INPUT_JOB_LIST=$1
34 if [ ! -f $JENKINS_INPUT_JOB_LIST ]
35 then
36 echo "ERROR File not found: $JENKINS_INPUT_JOB_LIST"
37 exit 1
38 fi
Jim Zucker4e24cac2016-04-05 08:06:38 -070039fi
40
Carlos Sanchez44deec32016-06-10 12:21:21 +020041# the war includes a # of plugins, to make the build efficient filter out
Jim Zucker4e24cac2016-04-05 08:06:38 -070042# the plugins so we dont install 2x - there about 17!
43if [ -d $JENKINS_HOME ]
44then
Carlos Sanchez44deec32016-06-10 12:21:21 +020045 TEMP_ALREADY_INSTALLED=$JENKINS_HOME/preinstalled.plugins.$$.txt
Jim Zucker4e24cac2016-04-05 08:06:38 -070046else
Carlos Sanchez44deec32016-06-10 12:21:21 +020047 echo "ERROR $JENKINS_HOME not found"
48 exit 1
Jim Zucker4e24cac2016-04-05 08:06:38 -070049fi
50
51JENKINS_PLUGINS_DIR=/var/jenkins_home/plugins
52if [ -d $JENKINS_PLUGINS_DIR ]
53then
Carlos Sanchez44deec32016-06-10 12:21:21 +020054 echo "Analyzing: $JENKINS_PLUGINS_DIR"
55 for i in `ls -pd1 $JENKINS_PLUGINS_DIR/*|egrep '\/$'`
56 do
57 JENKINS_PLUGIN=`basename $i`
58 JENKINS_PLUGIN_VER=`egrep -i Plugin-Version "$i/META-INF/MANIFEST.MF"|cut -d\: -f2|sed 's/ //'`
59 echo "$JENKINS_PLUGIN:$JENKINS_PLUGIN_VER"
60 done > $TEMP_ALREADY_INSTALLED
Jim Zucker4e24cac2016-04-05 08:06:38 -070061else
Carlos Sanchez44deec32016-06-10 12:21:21 +020062 JENKINS_WAR=/usr/share/jenkins/jenkins.war
63 if [ -f $JENKINS_WAR ]
64 then
65 echo "Analyzing war: $JENKINS_WAR"
66 TEMP_PLUGIN_DIR=/tmp/plugintemp.$$
Carlos Sanchez0ab40702016-08-05 10:44:58 +020067 for i in `jar tf $JENKINS_WAR | egrep '[^detached-]plugins.*\..pi' | sort`
Carlos Sanchez44deec32016-06-10 12:21:21 +020068 do
69 rm -fr $TEMP_PLUGIN_DIR
70 mkdir -p $TEMP_PLUGIN_DIR
71 PLUGIN=`basename $i|cut -f1 -d'.'`
72 (cd $TEMP_PLUGIN_DIR;jar xf $JENKINS_WAR "$i";jar xvf $TEMP_PLUGIN_DIR/$i META-INF/MANIFEST.MF >/dev/null 2>&1)
73 VER=`egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d\: -f2|sed 's/ //'`
74 echo "$PLUGIN:$VER"
75 done > $TEMP_ALREADY_INSTALLED
76 rm -fr $TEMP_PLUGIN_DIR
77 else
78 rm -f $TEMP_ALREADY_INSTALLED
79 echo "ERROR file not found: $JENKINS_WAR"
80 exit 1
81 fi
Jim Zucker4e24cac2016-04-05 08:06:38 -070082fi
83
Nicolas De Loofacb86492014-10-24 13:43:13 +020084REF=/usr/share/jenkins/ref/plugins
85mkdir -p $REF
Jim Zucker4e24cac2016-04-05 08:06:38 -070086COUNT_PLUGINS_INSTALLED=0
Carlos Sanchezc0475fd2015-04-29 11:55:48 +020087while read spec || [ -n "$spec" ]; do
Jim Zucker4e24cac2016-04-05 08:06:38 -070088
Nikolay Yurin390dc612015-04-20 14:46:29 +030089 plugin=(${spec//:/ });
Manuel Prinzdddb9652015-02-21 13:03:29 +010090 [[ ${plugin[0]} =~ ^# ]] && continue
91 [[ ${plugin[0]} =~ ^\s*$ ]] && continue
Nikolay Yurin390dc612015-04-20 14:46:29 +030092 [[ -z ${plugin[1]} ]] && plugin[1]="latest"
Carlos Sanchezd359b042015-07-02 13:06:14 +020093
94 if [ -z "$JENKINS_UC_DOWNLOAD" ]; then
95 JENKINS_UC_DOWNLOAD=$JENKINS_UC/download
96 fi
Jim Zucker4e24cac2016-04-05 08:06:38 -070097
Carlos Sanchez44deec32016-06-10 12:21:21 +020098 if ! grep -q "${plugin[0]}:${plugin[1]}" $TEMP_ALREADY_INSTALLED
Jim Zucker4e24cac2016-04-05 08:06:38 -070099 then
Carlos Sanchez44deec32016-06-10 12:21:21 +0200100 echo "Downloading ${plugin[0]}:${plugin[1]}"
Jim Zucker4e24cac2016-04-05 08:06:38 -0700101 curl --retry 3 --retry-delay 5 -sSL -f ${JENKINS_UC_DOWNLOAD}/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o $REF/${plugin[0]}.jpi
102 unzip -qqt $REF/${plugin[0]}.jpi
Carlos Sanchez44deec32016-06-10 12:21:21 +0200103 COUNT_PLUGINS_INSTALLED=`expr $COUNT_PLUGINS_INSTALLED + 1`
Jim Zucker4e24cac2016-04-05 08:06:38 -0700104 else
Carlos Sanchez44deec32016-06-10 12:21:21 +0200105 echo " ... skipping already installed: ${plugin[0]}:${plugin[1]}"
Jim Zucker4e24cac2016-04-05 08:06:38 -0700106 fi
107done < $JENKINS_INPUT_JOB_LIST
108
109echo "---------------------------------------------------"
110if [ $COUNT_PLUGINS_INSTALLED -gt 0 ]
111then
Carlos Sanchez44deec32016-06-10 12:21:21 +0200112 echo "INFO: Successfully installed $COUNT_PLUGINS_INSTALLED plugins."
Jim Zucker4e24cac2016-04-05 08:06:38 -0700113
Carlos Sanchez44deec32016-06-10 12:21:21 +0200114 if [ -d $JENKINS_PLUGINS_DIR ]
115 then
116 echo "INFO: Please restart the container for changes to take effect!"
117 fi
Jim Zucker4e24cac2016-04-05 08:06:38 -0700118else
Carlos Sanchez44deec32016-06-10 12:21:21 +0200119 echo "INFO: No changes, all plugins previously installed."
Jim Zucker4e24cac2016-04-05 08:06:38 -0700120
121fi
122echo "---------------------------------------------------"
123
124#cleanup
125rm $TEMP_ALREADY_INSTALLED
126exit 0