Jenkins is an open-source tool which allows you to maintain your software in an efficient methodology. It allows you to play nice with the practice of CI (Continuous Integration) as well as CD (Continuous Delivery). It takes you from the building stages of your software, to testing and documentation, all the way to deployment for clients to be able to use it. It is also to be noted that Jenkins is written in Java, and relies on servers like Apache Tomcat to run.
However, in case you see an error message like this:
‘Failed to start jenkins continuous integration server’
when trying to start the Jenkins service, it could end up being peculiarly frustrating. Many developers have their career depending on such occasions, while others may end up facing terrible business consequences.
Just kidding. It’s not that serious at all. Nevertheless, it’s still enough to wipe your sleep off. So pay close attention as I tell you how to save yourself from this dreadful error message!
Why did Jenkins continuous integration server fail to start?
Improper Java installation
The large mass of the cause for this error message include improper installation of OpenJDK. In very simple terms, if you don’t have java properly installed in your machine, then you may be unable to run the jenkins server. When installing the Jenkins server, Java will automatically be installed if it is not already. However, automatically installing it is not recommended as the symlinks might not be properly created, as well as the path might not be set. So the better option is to install it manually.
Log directory not found
Server applications largely rely on log files to keep track of server operations. Which is why, a log directory where all the log files will be stored is a must for server applications to operate. If you don’t have that directory in your system, and the server is unable to find it while startup, you’re quite likely to get the error message. In other circumstances, you may have the directory, but the user through which you’re trying to run the server does not have permission to write data on that directory. In this case, you’ll need to change the permissions for that directory too.
Port for Jenkins already occupied
The default port of Jenkins is 8080. If another server is using this port, then Jenkins will not be able to start. Port 80 is the default port for Apache and other HTTP servers, but at times these servers may be assigned to use port 8080 instead, which is also a very common one. If this is the reason for your error message, then you’ll either need to disable the program using port 8080, or change the port number for jenkins to something else.
In the next section, we’ll discuss all the different ways you can eliminate the error message, without causing other corresponding errors to encounter in the process.
Fix the “failed to load Jenkins continuous integration Server” error
Restart the Jenkins server
The first thing you’d prefer doing before you try out any other method is to see if you can restart the jenkins server. Try running the following commands in your terminal:
$ sudo systemctl stop jenkins $ sudo systemctl disable jenkins $ sudo systemctl start jenkins
After trying the above, if you see no further errors, this means that you;ve bypassed the issue, but if it turns out to be the same as before, proceed to the other methods.
Start Jenkins using systemctl
In newer versions of Ubuntu and Debian, you can use the systemctl command instead of the service command to start, stop, enable or disable services in your Linux machine. If you were using the service command to start jenkins, you might as well try to use this command instead as mentioned in the previous section:
$ sudo systemctl start jenkins
Instead of using:
$ sudo service jenkins start
This might not be the most reliable fix, but what’s it in to try anyway? There sure are differences between how the two commands function. You may wish to search out for their differences to further clarify that, if you may.
Create the log directory for Jenkins
If you don’t have the log directory in your system required by Jenkins to function, you’ll first need to create that if you wish to surpass the issue. To do this, execute the following command in your terminal:
$ sudo mkdir -p /var/log/jenkins
Change permission for /var/lib/jenkins/ directory
A very common problem for many users is that the user through which they are trying to run the server does not have the permission to access the directory called “/var//lib/jenkins”.This folder is used by the jenkins server to store dynamic files. If the user does not have permission to write to this directory, then you’d probably be unable to run the server. To fix this, execute the following in your terminal:
$ sudo chown <username> /var/lib/jenkins
Make sure to replace the <username> with the actual name of the user you’re trying to run the server with.
Manually install OpenJDK
This is yet another common occurrence of issues which cause the error message to be shown for jenkins. If you haven’t installed java before you had installed the jenkins server, java will then be automatically installed. But this would not be ideal as the java runtime path needs to be added in the global path variable of your system. Otherwise, Jenkins server will not be able to run as it solely relies on Java. The best way to get your way round this is to manually install Java, by running:
$ sudo apt-get install openjdk-11-jre
Newer versions of Jenkins require at least Java version 11. If you’re using an older version of Jenkins, then installing an older version of Java as well would be the better way to go. Consider installing JDK version 9 if you’re using Jenkins v2 or below:
$ sudo apt-get install openjdk-9-jre
Add Java executable directory to global path
This is a very crucial step for fixing the error message. If you’ve already installed java previous, but you’re still unable to run the Jenkins server, this might be due to the fact that the directory to the Java executable file is not listed in the Path variable. To add that directory to the Global PATH variable of your system, add the following line of code in your .bashrc file (if you’re using the bash shell. If it is ZSH for you, then include this in .zshrc file instead, located in your home directory):
$ export PATH=$PATH:/usr/lib/jvm/java-<version_number>-openjdk-amd64/bin/java
Pay very close attention here. Don’t just copy paste the above and directly execute it in your terminal. You need to change the <version_number> with the actual version of java that you have installed. It could be anything from 8, 9, 11, or even 17. If you’re unsure which version of Java you have installed, run this command:
$ java --vesion
You’ll get an output like the one below:
In the output, what you need to be looking for is the first number mentioned in the version. In this case, it is 11, so in the previous command, I’d replace <version_name>, with 11.
This should hopefully fix the issue for most of the users.
Check if port 8080 is occupied
If some other program is occupying port 8080, then you need to either disable that program, or change the port number which is used by Jenkins. But to figure out which server is occupying that port in the first place, you’d need to execute the following commands:
$ sudo apt-get install net-tools $ sudo netstat -antup | grep 8080
In my case, this is the output that I got:
Here, I can see that the Apache2 server is occupying port 80. If the terminal hadn’t returned any outputs, that would’ve meant that no program was occupying port 8080.
Now I have two options. Either I’ll have to stop and disable the apache2 server, if I don’t need it at present, or I’ll have to change the port for Jenkins if I wish for both to run simultaneously.
Disable the program occupying port 8080
If you choose to disable to program yourself, then you’d want to run the following command:
$ sudo systemctl stop <program_name> $ sudo systemctl disable <program_name>
Make sure to replace the <program_name> with the actual name of the program. In my case, the command would be:
$ sudo systemctl stop apache2 $ sudo systemctl disable apache2
Change port number for Jenkins
If you prefer to run both the server together, then you’d have to change the port number for the Jenkins server. To do this, first open up the configuration file for Jenkins by using a text editor like nano:
$ sudo nano /etc/default/jenkins
Inside this file, search for the line “HTTP_PORT=8080”. Here, change the port 8080 to something else. For example, I’m using:
You can change it to anything as long as it is 4-digits, is easy to remember, and is not used by other programs. Once you’re done, save and exit the file. Now try starting the jenkins server once again:
$ sudo systemctl start jenkins
Wala! You should now be able to run the jenkins server without any further issues, if you’re properly following the fixes mentioned.
I’m hopeful that you’ll now be able to run the jenkins server without having to see the face of the error message again in your machine. However, there may be even more instances of issues which cause the error message to occur. It would not be possible to compile every other problem a user might face with it, but I’ve tried my best to convey to you the most relevant ones that I could figure out. Luckily, if your specific error does not resemble any of the above, and does not fix the issues, checking out the log files under the /var/log/jenkins directory should give you a better insight about where the problem has occurred.