Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 1 | #! /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 Yurin | 390dc61 | 2015-04-20 14:46:29 +0300 | [diff] [blame] | 5 | # |
Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 6 | # FROM jenkins |
| 7 | # COPY plugins.txt /plugins.txt |
Justin Clayton | 8aec15c | 2015-01-23 12:19:02 -0800 | [diff] [blame] | 8 | # RUN /usr/local/bin/plugins.sh /plugins.txt |
Nikolay Yurin | 390dc61 | 2015-04-20 14:46:29 +0300 | [diff] [blame] | 9 | # |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 10 | # Note: Plugins already installed are skipped |
| 11 | # |
Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 12 | |
Jesse Glick | 9c8ddc4 | 2015-06-01 11:47:18 -0400 | [diff] [blame] | 13 | set -e |
| 14 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 15 | if [ -z "$1" ] |
| 16 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 17 | echo " |
| 18 | USAGE: |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 19 | Parse a support-core plugin -style txt file as specification for jenkins plugins to be installed |
| 20 | in the reference directory, so user can define a derived Docker image with just : |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 21 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 22 | FROM jenkins |
| 23 | COPY plugins.txt /plugins.txt |
| 24 | RUN /usr/local/bin/plugins.sh /plugins.txt |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 25 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 26 | Note: Plugins already installed are skipped |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 27 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 28 | " |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 29 | exit 1 |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 30 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 31 | JENKINS_INPUT_JOB_LIST=$1 |
| 32 | if [ ! -f $JENKINS_INPUT_JOB_LIST ] |
| 33 | then |
| 34 | echo "ERROR File not found: $JENKINS_INPUT_JOB_LIST" |
| 35 | exit 1 |
| 36 | fi |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 37 | fi |
| 38 | |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 39 | # the war includes a # of plugins, to make the build efficient filter out |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 40 | # the plugins so we dont install 2x - there about 17! |
| 41 | if [ -d $JENKINS_HOME ] |
| 42 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 43 | TEMP_ALREADY_INSTALLED=$JENKINS_HOME/preinstalled.plugins.$$.txt |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 44 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 45 | echo "ERROR $JENKINS_HOME not found" |
| 46 | exit 1 |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 47 | fi |
| 48 | |
| 49 | JENKINS_PLUGINS_DIR=/var/jenkins_home/plugins |
| 50 | if [ -d $JENKINS_PLUGINS_DIR ] |
| 51 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 52 | echo "Analyzing: $JENKINS_PLUGINS_DIR" |
| 53 | for i in `ls -pd1 $JENKINS_PLUGINS_DIR/*|egrep '\/$'` |
| 54 | do |
| 55 | JENKINS_PLUGIN=`basename $i` |
| 56 | JENKINS_PLUGIN_VER=`egrep -i Plugin-Version "$i/META-INF/MANIFEST.MF"|cut -d\: -f2|sed 's/ //'` |
| 57 | echo "$JENKINS_PLUGIN:$JENKINS_PLUGIN_VER" |
| 58 | done > $TEMP_ALREADY_INSTALLED |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 59 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 60 | JENKINS_WAR=/usr/share/jenkins/jenkins.war |
| 61 | if [ -f $JENKINS_WAR ] |
| 62 | then |
| 63 | echo "Analyzing war: $JENKINS_WAR" |
| 64 | TEMP_PLUGIN_DIR=/tmp/plugintemp.$$ |
| 65 | for i in `jar tf $JENKINS_WAR|egrep 'plugins'|egrep -v '\/$'|sort` |
| 66 | do |
| 67 | rm -fr $TEMP_PLUGIN_DIR |
| 68 | mkdir -p $TEMP_PLUGIN_DIR |
| 69 | PLUGIN=`basename $i|cut -f1 -d'.'` |
| 70 | (cd $TEMP_PLUGIN_DIR;jar xf $JENKINS_WAR "$i";jar xvf $TEMP_PLUGIN_DIR/$i META-INF/MANIFEST.MF >/dev/null 2>&1) |
| 71 | VER=`egrep -i Plugin-Version "$TEMP_PLUGIN_DIR/META-INF/MANIFEST.MF"|cut -d\: -f2|sed 's/ //'` |
| 72 | echo "$PLUGIN:$VER" |
| 73 | done > $TEMP_ALREADY_INSTALLED |
| 74 | rm -fr $TEMP_PLUGIN_DIR |
| 75 | else |
| 76 | rm -f $TEMP_ALREADY_INSTALLED |
| 77 | echo "ERROR file not found: $JENKINS_WAR" |
| 78 | exit 1 |
| 79 | fi |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 80 | fi |
| 81 | |
Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 82 | REF=/usr/share/jenkins/ref/plugins |
| 83 | mkdir -p $REF |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 84 | COUNT_PLUGINS_INSTALLED=0 |
Carlos Sanchez | c0475fd | 2015-04-29 11:55:48 +0200 | [diff] [blame] | 85 | while read spec || [ -n "$spec" ]; do |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 86 | |
Nikolay Yurin | 390dc61 | 2015-04-20 14:46:29 +0300 | [diff] [blame] | 87 | plugin=(${spec//:/ }); |
Manuel Prinz | dddb965 | 2015-02-21 13:03:29 +0100 | [diff] [blame] | 88 | [[ ${plugin[0]} =~ ^# ]] && continue |
| 89 | [[ ${plugin[0]} =~ ^\s*$ ]] && continue |
Nikolay Yurin | 390dc61 | 2015-04-20 14:46:29 +0300 | [diff] [blame] | 90 | [[ -z ${plugin[1]} ]] && plugin[1]="latest" |
Carlos Sanchez | d359b04 | 2015-07-02 13:06:14 +0200 | [diff] [blame] | 91 | |
| 92 | if [ -z "$JENKINS_UC_DOWNLOAD" ]; then |
| 93 | JENKINS_UC_DOWNLOAD=$JENKINS_UC/download |
| 94 | fi |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 95 | |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 96 | if ! grep -q "${plugin[0]}:${plugin[1]}" $TEMP_ALREADY_INSTALLED |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 97 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 98 | echo "Downloading ${plugin[0]}:${plugin[1]}" |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 99 | curl --retry 3 --retry-delay 5 -sSL -f ${JENKINS_UC_DOWNLOAD}/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o $REF/${plugin[0]}.jpi |
| 100 | unzip -qqt $REF/${plugin[0]}.jpi |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 101 | COUNT_PLUGINS_INSTALLED=`expr $COUNT_PLUGINS_INSTALLED + 1` |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 102 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 103 | echo " ... skipping already installed: ${plugin[0]}:${plugin[1]}" |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 104 | fi |
| 105 | done < $JENKINS_INPUT_JOB_LIST |
| 106 | |
| 107 | echo "---------------------------------------------------" |
| 108 | if [ $COUNT_PLUGINS_INSTALLED -gt 0 ] |
| 109 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 110 | echo "INFO: Successfully installed $COUNT_PLUGINS_INSTALLED plugins." |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 111 | |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 112 | if [ -d $JENKINS_PLUGINS_DIR ] |
| 113 | then |
| 114 | echo "INFO: Please restart the container for changes to take effect!" |
| 115 | fi |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 116 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame^] | 117 | echo "INFO: No changes, all plugins previously installed." |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 118 | |
| 119 | fi |
| 120 | echo "---------------------------------------------------" |
| 121 | |
| 122 | #cleanup |
| 123 | rm $TEMP_ALREADY_INSTALLED |
| 124 | exit 0 |