Updating the .war file of your containerized Jenkins instance

In some cases, after you log in to Jenkins and go to ‘Manage Jenkins’, it will show you a message saying “New version of Jenkins (x) is available for download (changelog)”. If you click ‘download’ it will start to download the latest .war Jenkins file. Here we are going to see the installation process of that file if you are running Jenkins in a docker container. If you installed Jenkins with a different method, the process to update the .war file may be different.

What is the Jenkins .war file?

According to the Jenkins official documentation, it is “The Jenkins Web application ARchive (WAR)” that “bundles Winstone, a Jetty servlet container wrapper, and can be started on any operating system or platform with a version of Java supported by Jenkins”. If you have a server with a compatible Java installation, you can use java to invoke this file and spin up a Jenkins instance.

Finding the path of the outdated .war file

From the Jenkins GUI of your target instance, go to ‘Manage Jenkins’ and then click on ‘System Information’. Look for the property ‘executable-war’ to see where to find the outdated .war file:

Common paths include ‘/usr/share/jenkins‘ (Ubuntu) or ‘/usr/lib/jenkins‘ (CentOS). Another way to do it is by going to the host and run a ‘docker exec’ command to find the .war file (replace <container_id> with the ID of the Jenkins container):

docker exec <container_id> find / -name "*.war"

In the results, there should be a jenkins.war file.

Backing up the outdated .war file

Before continuing the process, we are going to back up the outdated .war file in the host. To do that, you can use the following command:

docker cp <container_id>:<path_of_outdated_war_file> <path_of_the_backup_file>

Downloading and copying the updated .war file to the Jenkins container

In the host of the Jenkins container, we are going to download the updated .war file. For that, we can use the following command:

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

Now, we will stop the Jenkins container to copy the new and updated .war file:

docker stop <container_id>

To copy the .war file use:

docker cp <path_of_the_updated_file> <container_id>:<path_of_outdated_war_file> 

To finish the process, restart the container:

docker restart <container_id>

Confirm that Jenkins is working as expected. If that is not the case, restore the backup and check with docker logs what caused the issue.

| Theme: UPortfolio