Each day new tools are developed and released in the market. One of these is Jenkins which was initially released on 2nd February 2011 and originally written by Kohsuke Kawaguchi.
What is Jenkins?
Jenkins is an open-source continuous integration tool that allows the continuous development, testing, and deployment of newly created codes. It is written in Java.
Jenkins is one of the top devops tools in the market. When Jenkins did not exist, developers around the world would build the code and commit changes to the source code. All the codes would be pulled only at night (or during day time depending on the timezone of the developers). This code was then tested and the new build acted as the foundation for the next build.
Jenkins is an essential tool to learn when you want to get expertise in Devops. With Jenkins, the first step of committing changes to the source code remained the same. But now, code could be pulled whenever a new commit was made. Additionally, changes made to the source code could also be done continuously. This was made possible because the testing and verification services were brought into the build environment
The entire process could now be smooth and continuous.
What is continuous integration?
As a developer, you can call a code that you are working on from the repository. You will then be able to submit the code to a CI server at any time. This server validates and passes any tests that the tester may have created.
If the code doesn’t pass the test, then it is sent back to the developer for improvement. This safeguards the build from being broken.
Another benefit is that the developer doesn’t have to run tests remotely on their system. A large number of tests can take up a lot of time. Delegating this testing to another system like the CI server makes the entire software creation process more efficient.
If any code errors come up that are not accounted for in the CI server, those can be easily communicated between the tester and the developer.
The overarching benefit from using this is that the code can be deployed faster. Ultimately, customers can see the newer version with fixes and improvements quickly than ever before.
Other continuous integration tools include:
- Travis CI
- Apache Gump
Why Jenkins was needed
This is a scenario that all developers can relate to: you write a piece of code and save it to a code repository.
Now the problem is that the actual commits that are sent to the repository are not consistent. They are erratic and irregular. Developers might be spread throughout the world. Some might be living in the UK, some in India, some in the US, and some in the Philippines. Everyone is working at different times and has different amounts of code going into the code repository.
This leads to issues in integration which leads to ‘delay in testing.’ on top of it, the bugs just keep increasing. This creates delays in the overall project and release of the software.
In the past, developers had to wait for the entire code to be built before it could be tested for errors. So not only was the final delivery of project delayed, there was no iterative process in place for fixing the code. Efficiency approached zero.
The Jenkins process/ pipeline
- In the development phase of any software project, you write the code and commit it to a Git server or a similar type of server. When using Jenkins, it is the Jenkins server you commit the code to.
- The Jenkins server will then create a build of your code. Part of this build process is running the code through tests. You would already be doing this but Jenkins will run tests of its own. If your team has some other tests to validate the code, those can be run in the Jenkins environment as well.
- If all the tests are passed, then you can then release and deploy plus deliver the code to a production environment.
The above steps outline the continuous integration/ continuous delivery process. The big benefit is that you can move from development to production really quickly since Jenkins automates the entire process.
Characteristics of Jenkins
Some features of Jenkins that you will encounter as you work with it:
- Jenkins is a self-contained Java program. It is ready to run with packages for Mac OS X, Windows, Unix-like OS
- It can be easily set up and configured. You only need its web interface which includes built-in help and error check-ins
- Jenkins can be extended via ita plug-in architecture. This provides infinite possibilities for how Jenkins can be configured for one’s own needs.
- It has hundreds of plugins in the Update Center
- Jenkins integrates with every tool in the CD and CI toolchain
- It can easily distribute work across multiple machines. This allows for faster build, tests, and deployment across all platforms.
The Jenkins architecture
The Jenkins architecture can be broken down into two components (visualized next to each other): the human component and the Jenkins component.
The human component consists of developers who write the code and submit it to a source code repository.
Jenkins comes in now. The CI server regularly checks the repository, pulls in any new code that’s been made available, and runs tests against it.
The Build server then builds the code into an executable file. A conversion of Java file into the JAR file takes place. In case the build process fails, a notification is sent to the developers so they can change their code. Maven is an example of a build server that is available as a plugin in Jenkins.
In the final stage, test scripts are executed. These test scripts can be written in Selenium which is another plugin available in Jenkins. Jenkins deploys the build application to the test server. In the case of test failure, feedback is again sent to the developers.
If all the above stages are passed smoothly, then the testes code/ application is deployed to the production server.
A limitation in Jenkins
If developers are writing codes in multiple languages (PHP, Java, HTML, etc.) then multiple builds will have to be made and managed. Jenkins doesn’t provide this facility on a single server. We’ll need a distributed Jenkins architecture to get over this limitation.
The Jenkins Master-Slave architecture
The starting point for understanding all the workings of Jenkins is the remote source code repository. This could be GitHub or any other repository. Next comes in the master-slave architecture.
The Jenkins server accesses the master environment which branches off into multiple slave environments. This allows you to create multiple builds and multiple tests and production environments simultaneously across the entire architecture. The slave components can build different versions for different operating systems while the master component oversees them.
Both the components communicate with each other via TCP/ IP protocol.
Advantages and disadvantages of Jenkins
First off, let’s take a look at the various benefits that Jenkins provides to any team that uses it:
It lowers the effort that goes into repeated coding
A command prompt can be converted into a GUI button click by wrapping a Jenkins script as a Jenkins job.
It can be synchronized with Slack
Slack is a popular platform for team communication and it can be synchronized with Jenkins.
Great support for project management
Each activity is wrapped as a Jenkins job. For each job, completion time can be measured and success/ failure can be identified using SDK or REST API.
Support also comes in the form of plugins. As mentioned above, Jenkins has hundreds of plugins available for extensibility. A few of these include Pipeline plugin, Build-timeout, Timestamper, thinBackup, etc.
Only the best goes in the production environment
Due to continuous integration, the code is tested well and only merged when all the tests shave been passed successfully. This ensures that the master builds are not broken. This further prevents any broken code from reaching the production environment. If the master build is broken, a warning to all developers can be triggered.
Increased code coverage
Code coverage is ensured through testing. The results of tests are displayed on the build pipeline. This keeps the testing process transparent for all team members.
In terms of disadvantages, this is where Jenkins falls short. They have been pointed out by developers themselves:
- It’s not cloud-based
- There is a steep learning curve
- The UI feels un-intuitive, especially for new users
- It doesn’t allow a team member to readily see the commits made by another team member. For a release manager, tracking the overall release progress of a project becomes difficult.
- Since it is open-source and you can customize a great deal due to the plugins, finding support for your particular problems might be difficult.
Acing a Jenkins interview
While the above is a thorough overview of Jenkins, it is not enough for interviews. You’ll need more in-depth knowledge which can only come from working with the tool and studying its theoretics. Here are some frequently asked questions to help you with the latter:
What are the pre-requisites for using Jenkins?
You’ll need: access to a source code management repository like SVN or GIT repository and a build script that should work like a Mavens build script.
What do Jenkins file, post-section, and agent mean?
Jenkins file is the text file that is checked into source control and contains information about the Jenkins pipeline.
Post-section runs at the end of the pipeline’s execution and is used when we have to perform some other tasks at the end of a pipeline and add some notification.
Agent is a directive/ command to tell Jenkins to execute the pipeline in a particular manner and order.
What is the use of pipelines in Jenkins?
Using the Pipeline plugin, one can create pipelines in Jenkins. These are used to give a view of the stages/ tasks to perform sequentially. Pipelines help teams in reviewing, editing, and iterating tasks.
This does not mean that once a pipeline has been created it can’t be interfered with. A pipeline is durable, meaning it can stop and a human can interview to further direct its flow.
Can we start Jenkins manually? If yes, how?
Yes, Jenkins can be opened manually. The steps for it are:
- Go to the Jenkins installation directory from the command line prompt
- Use the ‘Jenkins.exe start’ command to start Jenkins
- To restart: use ‘Jenkins.exe restart’ and to stop it ‘Jenkins.exe stop’
How to copy Jenkins from one server to another?
- Copy the Jenkins directory from the first server. Paste it to other servers.
- Clone a job directory with a different name and to make a copy of an existing job
- Rename the directory to rename the existing job
What is the salary of a Jenkins engineer?
In India, the median salary for a Jenkins build and release engineer is INR 6,15,756. Someone with 1-4 years of experience can earn an average salary of INR 4,90,857. This includes overtime, tips, and bonuses.
A build and release engineer with 5-9 years of experience (mid-career) can earn an average salary of INR 9,89,000. Finally, an experienced professional with 10-19 years of experience can earn 13,50,000. Pune, Bangalore, and Mumbai have been reported to pay higher than average salaries.
The most popular skills for Jenkins build and release engineers are:
- Build management
- Release management
- Shell scripting
Armed with the above information, we hope you have a solid foundation for understanding Jenkins and cracking any Jenkins related interview. No matter the field, the final determiner of your status and pay is your skills. So, keep learning and improving. Good luck!
If you’re interested to learn more about big data, check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.