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 | |
Carlos Sanchez | 0ab4070 | 2016-08-05 10:44:58 +0200 | [diff] [blame] | 15 | echo "WARN: plugins.sh is deprecated, please switch to install-plugins.sh" |
| 16 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 17 | if [ -z "$1" ] |
| 18 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 19 | echo " |
| 20 | USAGE: |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 21 | 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 Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 23 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 24 | FROM jenkins |
| 25 | COPY plugins.txt /plugins.txt |
| 26 | RUN /usr/local/bin/plugins.sh /plugins.txt |
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 | Note: Plugins already installed are skipped |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 29 | |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 30 | " |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 31 | exit 1 |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 32 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 33 | JENKINS_INPUT_JOB_LIST=$1 |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 34 | if [ ! -f "$JENKINS_INPUT_JOB_LIST" ] |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 35 | then |
| 36 | echo "ERROR File not found: $JENKINS_INPUT_JOB_LIST" |
| 37 | exit 1 |
| 38 | fi |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 39 | fi |
| 40 | |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 41 | # 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] | 42 | # the plugins so we dont install 2x - there about 17! |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 43 | if [ -d "$JENKINS_HOME" ] |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 44 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 45 | TEMP_ALREADY_INSTALLED=$JENKINS_HOME/preinstalled.plugins.$$.txt |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 46 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 47 | echo "ERROR $JENKINS_HOME not found" |
| 48 | exit 1 |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | JENKINS_PLUGINS_DIR=/var/jenkins_home/plugins |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 52 | if [ -d "$JENKINS_PLUGINS_DIR" ] |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 53 | then |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 54 | echo "Analyzing: $JENKINS_PLUGINS_DIR" |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 55 | for i in "$JENKINS_PLUGINS_DIR"/*/; do |
| 56 | JENKINS_PLUGIN=$(basename "$i") |
| 57 | JENKINS_PLUGIN_VER=$(egrep -i Plugin-Version "$i/META-INF/MANIFEST.MF"|cut -d: -f2|sed 's/ //') |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 58 | echo "$JENKINS_PLUGIN:$JENKINS_PLUGIN_VER" |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 59 | done >"$TEMP_ALREADY_INSTALLED" |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 60 | else |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 61 | JENKINS_WAR=/usr/share/jenkins/jenkins.war |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 62 | if [ -f "$JENKINS_WAR" ] |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 63 | then |
| 64 | echo "Analyzing war: $JENKINS_WAR" |
| 65 | TEMP_PLUGIN_DIR=/tmp/plugintemp.$$ |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 66 | while read -r i <&3; 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" || exit; 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/ //') |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 72 | echo "$PLUGIN:$VER" |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 73 | done 3< <(jar tf "$JENKINS_WAR" | egrep '[^detached-]plugins.*\..pi' | sort) > "$TEMP_ALREADY_INSTALLED" |
| 74 | rm -fr "$TEMP_PLUGIN_DIR" |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 75 | else |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 76 | rm -f "$TEMP_ALREADY_INSTALLED" |
Carlos Sanchez | 44deec3 | 2016-06-10 12:21:21 +0200 | [diff] [blame] | 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 |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 85 | while read -r 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 |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 89 | [[ ${plugin[0]} =~ ^[[:space:]]*$ ]] && 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 | |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [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]}" |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [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" |
| 101 | (( 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 |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 105 | done < "$JENKINS_INPUT_JOB_LIST" |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 106 | |
| 107 | echo "---------------------------------------------------" |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 108 | if (( "$COUNT_PLUGINS_INSTALLED" > 0 )) |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 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 |
Charles Duffy | 3eec42c | 2016-09-20 12:11:33 -0500 | [diff] [blame] | 123 | rm "$TEMP_ALREADY_INSTALLED" |
Jim Zucker | 4e24cac | 2016-04-05 08:06:38 -0700 | [diff] [blame] | 124 | exit 0 |