Categories
Uncategorized

Setting up Jenkins to Auto-Update

When setting up Jenkins, you’ll have to perform upgrades on the system yourself. You can do this pretty easily, but let’s automate the process so that each night, Jenkins will download and install the latest version.

To do this you’ll need to have SSH access to the server.

Creating Upgrade Script

First, SSH into the server.

Create a bin/ folder in the user’s directory:

cd ~
mkdir bin

If it doesn’t already exist, create a .bash_profile file and add the following:

 export PATH=$PATH:/home/<YOUR_USER>/bin

Now create the script file for use:

cd bin
touch upgrade-jenkins

Create a script with the following contents:

#!/bin/bash

sudo wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
sudo mv jenkins.war /usr/share/jenkins/jenkins.war
sudo systemctl restart jenkins

And make the script executable:

chmod u+x upgrade-jenkins

You can finally test the script by calling upgrade-jenkins. When it runs, Jenkins should restart with the latest version.

Setting up for Automatic Updates

The next step is setting up the script to run each night at some point to promote automatic upgrades, so you don’t have to worry about updating the system. To do this, we’ll create a cron job that runs the above script once a day.

Set up a crontab file using crontab -e, and add the following to the file to run everyday at 3am. (make sure to check date to see if the system is using UTC):

0 3 * * * upgrade-jenkins

Once this is in place, you’ll be running the script above once a day, which will download and run the latest version of Jenkins on a regular basis.


Reference:

https://www.taniarascia.com/how-to-create-and-use-bash-scripts/

Leave a Reply

Your email address will not be published. Required fields are marked *