110

I have a machine with Ubuntu 12.04 and have installed Jenkins ver. 1.424.6 using apt-get based on *this guide*, but there is a new version:

New version of Jenkins (1.447.2) is available for download (changelog).

If I press download, I get a jenkins.war file... but how do I use that for upgrading my current installation? or is that not possible before the apt repositories gets updated?

0

15 Answers 15

189

You can overwrite the existing jenkins.war file with the new one and then restart Jenkins.

This file is usually located in /usr/share/jenkins.

If this is not the case for your system, in Manage Jenkins -> System Information, it will display the path to the .war file under executable-war.

7
  • 16
    On my machine its located in /usr/share/jenkins/. After copying and restarting with "service jenkins restart" it still shows the old version and suggest an update - what am I doing wrong?
    – u123
    Jun 16, 2012 at 9:58
  • 2
    What about consistency of configuration files after the upgrade? Do you need to set up the whole thing again? Do they support backward compatibility?
    – Denys S.
    Sep 27, 2013 at 14:48
  • @DEnysS. it'll keep all your configurations. I removed the existing war file and moved the new one from Downloads to /usr/share/jenkins and it worked perfectly. (Aptitude didn't show an update for jenkins) Mar 20, 2014 at 21:43
  • 1
    step by step of @bcmcfc 's answer here: stackoverflow.com/a/46733405/1404135
    – 3z33etm
    Oct 13, 2017 at 15:37
  • 1
    /usr/lib/jenkins Jun 2, 2019 at 3:56
47
#on ubuntu, in /usr/share/jenkins:

sudo service jenkins stop
sudo mv jenkins.war jenkins.war.old
sudo wget https://updates.jenkins-ci.org/latest/jenkins.war
sudo service jenkins start
4
  • 3
    Great! Last stable link is also useful: updates.jenkins-ci.org/stable/latest/jenkins.war Jan 24, 2018 at 10:31
  • Best Practice, easy to do. Thanks for this answer Jun 16, 2018 at 6:47
  • Phew! You helped me from getting a heart attack in the middle of the night with our Jenkins forcing us to upgrade and not running any of its plugins
    – Emjey
    Jun 27, 2019 at 21:18
  • I think you don't need to stop service first, you could just use "restart" after replacing the ".war" file
    – lezhumain
    Mar 21, 2023 at 14:20
34

If you have installed Jenkins via apt-get, you should also update Jenkins via apt-get to avoid future problems. Updating should work via "apt-get update" and then "apt-get upgrade".

For details visit the following URL:

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu

3
  • 13
    +1 b/c you never know what Ubuntu changed about the Jenkins configuration. Adding to this: pkg.jenkins-ci.org/debian provides updated packages installable via apt-get directly from the project.
    – mabi
    Sep 18, 2012 at 11:42
  • No need to update jenkins from war file if you do that mentioned above. I think this is the better way on Ubuntu. Feb 19, 2013 at 5:17
  • 11
    If you previously installed jenkins with apt-get but through the default Ubuntu package repository (i.e. without pkg.jenkins-ci.org/debian), you have to remove the default Ubuntu packages before installing the new one sudo apt-get remove jenkins jenkins-common then sudo apt-get install jenkins. If you do not do that, the update will fail in a trying to overwrite '/usr/share/jenkins/jenkins.war', which is also in package jenkins-common 1.424.6+dfsg-1ubuntu0.1 May 14, 2013 at 7:55
13
apt-get update
apt-get upgrade 

by far the easiest way to upgrade on linux, works like a charm everytime.

1
  • Similar on CentOS by the way, yum update jenkins should do it.
    – Nagev
    Jul 20, 2018 at 9:15
6

when you open the Jenkins panel it will show available package from their latest version. you can download it via wget command in the server.after download the latest package you should take .war backup file.

Eg-: wget http://updates.jenkins-ci.org/download/war/2.205/jenkins.war

Jenkins war file path for Ubuntu - /usr/share/jenkins/

Jenkins war file path for centos - /usr/lib/jenkins/

after taking backup overwrite the war file and restart the jenkins service.

Ubuntu - service jenkins restart , centos - systemctl restart jenkins.service

4

Though I wouldn't consider this as a valid answer to OP's question, I'd still emphasize that the best way to deploy Jenkins (and likely most if not all libraries/packages/software) on Ubuntu is to leverage aptitude (or apt-get) management system.

It is documented here: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu (notice that if you want to use the LTS build, hit on this repo http://pkg.jenkins-ci.org/debian-stable/)

So if by any chance you actually did use this approach, you'd simply do a apt-get upgrade jenkins

1
  • In theory you're right but that doesn't work when upgrading from the stock install. After installation of the latest package it is starting up but giving a 503 error. I followed the procedure written there and I had to apply Matthieu Rouget's solution in order to get a consistent pkg state.
    – Glenn Plas
    Mar 19, 2014 at 15:21
2

We run jenkins from the .war file with the following command.

java -Xmx2500M -jar jenkins.war --httpPort=3333 --prefix=/jenkins

You can even run the command from the ~/Downloads directory

2

I use this groovy script to download new war file

import java.util.concurrent.atomic.AtomicInteger

class ThreadHelper{
    static done = false;
    static starttime = System.currentTimeMillis()
    static synchronized printx (message) {    printf ("%5s seconds: %20s",(System.currentTimeMillis()-starttime)/1000.0 , message); println("") }
    def download(address)
    {
    def filename = new File(System.getenv()['CI_HOME'] + '/' + address.tokenize("/")[-1])
    println(filename.getCanonicalPath())
    def file = new FileOutputStream(filename)
    def out = new BufferedOutputStream(file)
    out << new URL(address).openStream()
    out.close()
    done=true;
    }

}

println("executing from ... "+ new File(".").getCanonicalPath())

def counter = new AtomicInteger();
    th = Thread.start {
    while(!ThreadHelper.done) {
    sleep 1000
    counter.incrementAndGet()
    print '.'
    }
}

th2 = Thread.start { new ThreadHelper().download("http://mirrors.jenkins-ci.org/war/latest/jenkins.war") }
th.join()
th2.join()

ThreadHelper.printx('done')

And another script shutsdown tomcat - copies the war and restarts it

We host it on windows 2008 and tomcat, I use sc query, sc config, sc stop, sc start to manage windows services

    set warname=jenkins

if '%name%' == 'trak' set warname=trak

pushd .
if '%name%'=='' goto badname
if '%warname%'=='' goto badname

if '%ci_home%'=='' goto badcihome

REM =====================================================
REM stop windows service
sc stop %name%

REM sleep for 5 seconds see http:\\stackoverflow.com\questions\1672338\how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos
ping 1.1.1.1 -n 1 -w 3000 > nul

rem replace forward slash with backward slash
set tomcat_dir=%ci_home:/=\%\instances\tomcat7-%name%

REM Create sub directory called bak-yymmdd-hhmmss
REM where yymmdd-hhmmss is a date-time stamp like 120601-142907

set hh=%time:~0,2%

REM Since there is no leading zero for times before 10 am, have to put in
REM a zero when this is run before 10 am.

if "%time:~0,1%"==" " set hh=0%hh:~1,1%

set yymmdd_hhmmss=%date:~12,2%%date:~4,2%%date:~7,2%-%hh%%time:~3,2%%time:~6,2%

set backupdir=bak-%yymmdd_hhmmss%

REM =====================================================
md %tomcat_dir%\logs\%backupdir%

cd %tomcat_dir%\logs

dir bak*
echo "nothing-to-log" >> force.log

REM move command will fail if there is nothing to move hence the force log statement above

call move *.* %backupdir%

REM =====================================================
rmdir %tomcat_dir%\webapps\%name% /q/s

echo f|xcopy %ci_home%\%warname%.war %tomcat_dir%\webapps\%name%.war /y

REM TODO===== something about jenkins plugins

REM =====================================================
cd "%tomcat_dir%\bin"
call catalina version

echo =====================================================
echo ====== removing %name%
call service remove %name%

echo =====================================================
echo ====== installing %name%
call service install %name%

echo on

REM setting service to start automatically, note that space before the word auto IS REQUIRED
sc config %name% start= auto

REM =====================================================
sc start %name%

popd

exit 0

goto done

:badname
echo 'name required - this will be used as windows service name as well'
pause
exit 1

:badcihome
echo 'CI home env var required - ci_home'
pause
exit 1

:done
2
https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Ubuntu

Once installed like this, you can update to the later version of Jenkins (when it comes out) by running the following commands:
-------
sudo apt-get update
sudo apt-get install jenkins
-------
(aptitude or apt-get doesn't make any difference.)
What does this package do?
Jenkins will be launched as a daemon up on start. See /etc/init.d/jenkins for more details.
The 'jenkins' user is created to run this service.
Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting Jenkins.
/etc/default/jenkins will capture configuration parameters for the launch like e.g JENKINS_HOME
By default, Jenkins listen on port 8080. Access this port with your browser to start configuration.
2

This could be done in two ways

  1. Directly download the .war file and replace it with the existing one.
  2. update directly from ubuntu

1st Method

If you are not able to find jenkins war file in standard path, you can goto Manage Jenkins → System Information, it will display the path to the .war file.

The common location of Jenkins war file on the ubuntu server is:

/usr/share/jenkins

Jump to jenkins home directory

cd /usr/share/jenkins

Stop the jenkins server

sudo service jenkins stop

Move existing jenkins war file

sudo mv jenkins.war jenkins.war.old

Download latest jenkins war file

sudo wget https://updates.jenkins-ci.org/latest/jenkins.war

Start the Jenkins server

sudo service jenkins start

Everything should be good now.

Troubleshooting steps

If you are running jenkins using root permissions, (which you should not be doing), you need to change the jenkins.war permissions.

$ sudo chown root:root jenkins.war

You can optionally restart the jenkins server using below command:

$ sudo /etc/init.d/jenkins restart

2nd Method

On ubuntu, you can also try the below two commands to update everything:

$ sudo apt-get update
$ sudo apt-get install jenkins --fix-missing
1

Mine is installed under /usr/share/jenkins I thought it was installed via apt-get so might want to check there as well.

Ubuntu 12.04.1

1

I didn't want to install the x11-common and other components that come bundled in the apt-get install approach, so I just downloaded the .war file and ran the command Francois mentioned. That worked nicely, but you have to write your own daemon script with that approach. Full details here: http://strem.in/stream/9488/Using-the-war-file-for-jenkins-ci

1

To Upgrade Jenkins WAR file, follow the steps below:

  • Stop Jenkins server using command: systemctl stop jenkins
  • Go to Jenkins war location: ex: /usr/lib/jenkins
  • Take a backup from jenkins.war: mv jenkins.war jenkins.war_bkp
  • Download Jenkins using wget or curl command: wget http://updates.jenkinsci.org/download/war/(version)/jenkins.war
  • Starting Jenkins server using command: systemctl start jenkins
  • Check Jenkins server status using command: systemctl status jenkin
1

On ubuntu, in /usr/share/jenkins:

sudo service jenkins stop
sudo mv jenkins.war jenkins.war.old
sudo wget https://updates.jenkins-ci.org/latest/jenkins.war
sudo service jenkins start
0
  • In the latest version of Jenkins, the jenkins.war file location has been changed.
  • updatedb && locate jenkins.war command can be used to check the new path which is: /usr/share/java/.
  • Replace the old .war file with the new one under /usr/share/java/ directory and restart the Jenkins to upgrade it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.