Skip to content

Instantly share code, notes, and snippets.

@matthewoestreich
Last active October 7, 2019 23:47
Show Gist options
  • Save matthewoestreich/436290f81973dc2175470267d043dc00 to your computer and use it in GitHub Desktop.
Save matthewoestreich/436290f81973dc2175470267d043dc00 to your computer and use it in GitHub Desktop.
Updates Jenkins based upon URL. You will need to change the paths below to fit your deployment.
#!/bin/bash
# USE LIKE:
# bash jenkinsUpdater.sh "updates.jenkins-ci.org/download/war/2.190.1/jenkins.war"
# Change these locations to suit your needs
BACKUP_ROOT_PATH=/usr/share/jenkins/backups
JENKINS_WAR_PATH=/usr/share/jenkins
DOWNLOAD_ROOT_PATH=~/downloads
URL=$1
CURRENT_DATE=`TZ=America/Chicago date +%m_%d_%Y__%I_%M_%S_%p`
JENKINS_WAR_FILE_PATH=$JENKINS_WAR_PATH/jenkins.war
BACKUP_PATH=$BACKUP_ROOT_PATH/$CURRENT_DATE
DOWNLOAD_PATH=$DOWNLOAD_ROOT_PATH/$CURRENT_DATE
printf "-- CREATING BACKUP PATH: \n $BACKUP_PATH\n\n"
mkdir $BACKUP_PATH
printf "-- CREATING DOWNLOAD PATH: \n $DOWNLOAD_PATH\n\n"
mkdir $DOWNLOAD_PATH
printf "-- BACKING UP JENKINS.WAR: \n $JENKINS_WAR_FILE_PATH \nTO BACKUP PATH: \n $BACKUP_PATH\n\n"
cp $JENKINS_WAR_FILE_PATH $BACKUP_PATH
printf "-- DOWNLOADING NEW WAR FILE FROM: \n $URL\n TO:\n $DOWNLOAD_PATH\n\n"
wget $URL -P $DOWNLOAD_PATH
printf "-- COPYING NEW WAR FILE\n\n"
cp $DOWNLOAD_PATH/jenkins.war $JENKINS_WAR_PATH
printf "-- STOPPING JENKINS\n\n"
systemctl stop jenkins
printf "-- STARTING JENKINS\n\n"
systemctl start jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment