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:

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

Now create the script file for use:

Create a script with the following contents:

And make the script executable:

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 sudo 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):

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.

If you’re running into issues, you can check the logs at: