Last active
July 21, 2016 14:07
-
-
Save spelcaster/207d8b2a65d5367b8621bbe3a2d4964f to your computer and use it in GitHub Desktop.
Script to download jenkins plugins using jenkins-cli in command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script should be used to download the most recent plugins for jenkins in command line | |
# You need Jenkins CLI (https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI) to use this script | |
JENKINS_CLI_JAR=/path/to/jenkins-cli.jar | |
JENKINS_PLUGIN_URL=http://updates.jenkins-ci.org/latest/ | |
JENKINS_PLUGIN_EXT=.hpi | |
JENKINS_PLUGIN_TMP=/tmp/jenkins/plugin | |
LIST_PLUGINS_CMD="java -jar ${JENKINS_CLI_JAR} -s http://localhost:8080/ list-plugins" | |
download_jenkins_plugins () | |
{ | |
local plugin_url="" | |
local filename="" | |
local retval=0 | |
for plugin in $(${LIST_PLUGINS_CMD} | awk '{print $1}'); do | |
plugin_url=${JENKINS_PLUGIN_URL}${plugin}${JENKINS_PLUGIN_EXT} | |
filename=${plugin}${JENKINS_PLUGIN_EXT} | |
echo "Downloading ${plugin} from ${plugin_url}" | |
curl --connect-timeout 5 -L ${plugin_url} > ${filename} | |
retval=$? | |
if [[ ${retval} -ne 0 ]] | |
then | |
>&2 echo "Failed to download ${plugin}" | |
>&2 echo "cURL error code: ${retval}" | |
fi | |
done | |
} | |
if [[ ! -d ${JENKINS_PLUGIN_TMP} ]] | |
then | |
echo "Creating jenkins plugin directory" | |
mkdir -vp ${JENKINS_PLUGIN_TMP} | |
fi | |
cd ${JENKINS_PLUGIN_TMP} | |
download_jenkins_plugins | |
cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great script! Congrats!