DevOps

The Complete Tutorial: A beginners guide to Jenkins

Learn the basics of Jenkins, where and how it is used. The article further deep dives into how to set up Jenkins from basics.

The Complete Tutorial: A beginners guide to Jenkins

Complete Jenkins Tutorial


Before, we learn what Jenkins is, we must understand what is Continuous Integration?

Continuous integration(CI) is a coding methodology and set of procedures that encourage development teams to constantly execute tiny code changes and check them into a version control repository. Teams need a standard method to integrate and evaluate changes because the majority of current apps require writing code utilizing a range of platforms and tools. A system of the automatic building, packaging, and testing of their applications is established via continuous integration.

By encouraging developers to commit code changes more frequently, a constant integration process improves cooperation and code quality.

What is Jenkins?

Jenkins is an open-source Continuous Integration server developed in Java that orchestrates a series of operations to automate the Continuous Integration process.

Jenkins provides support for all phases of the software development life cycle, including building, testing, documenting, deploying, and other phases.

Because it is a server-based application, a web server like Apache Tomcat is needed. Jenkins software’s ability to track recurring tasks that come up while a project is being developed is what made it so popular.

For instance, if your team is working on a project, Jenkins will continually test your project builds and let you know if there are any mistakes at the beginning of the process.

Jenkins Architecture

Jenkins manages distributed builds using a Master-Slave architecture. TCP/IP protocol is used in this design for communication between the slave and master.

Jenkins architecture is composed of two parts:

  • Jenkins Master/Server
  • Jenkins Slave/Node/Build Server

Jenkins Master/Server


Jenkins master schedules the jobs assigns slaves and sends builds to slaves to run the jobs. Additionally, it will keep track of whether the slaves are online or offline, retrieve the answers from the slaves on the build results, and output the build results on the console. Building jobs are divided up among a number of slaves.

Jenkins Slave/Node/Build Server

Jenkins server is a web dashboard that runs by default on port 8080 and is just driven by a war file. You may configure the jobs and projects via the dashboard, but the build happens in the slave nodes.

One Node/Slave is set up and operating in Jenkins Server by default. Using the ssh/jnlp/webstart protocols, you may also add extra nodes or slaves by providing an IP address, user name, and password.

Jenkins may even run build jobs directly in a distributed architecture.

The slaves’ responsibility is to carry out their defined tasks on the Jenkins Server, which includes completing build jobs assigned by the master. A project can be set up to always run on a certain slave computer or a specific kind of slave machine, or you can just let Jenkins choose the next available slave.

Jenkins servers and nodes/slaves may be configured on any servers, including Windows, Linux, and Mac, as Java is used in its development and is platform-independent.

Applications of Jenkins

Jenkins reduces the effort required for repetitive coding

Jenkins may be used to transform a command-line function into a GUI button click. The script may be packaged as a Jenkins task to do this. Jenkins tasks can be parameterised to be customised or to accept user input. As a result, thousands of lines of code can be avoided.

Integrating Different Jobs

Jenkins tasks are typically simple instruments. They accomplish minimal, limited goals. Jenkins has a pipeline plugin that enables the combining of several tasks. Pipelining offers advantages that Linux users are best able to comprehend. Both parallel and sequential combinations are viable.

Option for Manual Tests

When things are forced upon a central system, they may perform perfectly locally yet fail. This occurs because circumstances have changed by the time they push. Continuous Integration, which is carried out in a setting similar to a production environment, checks the code against the state of a code base at the time.

Expanded Coding Coverage

Code for test coverage may be checked by CI servers like Jenkins. Code coverage is increased through tests. Team members become more open and responsible as a result. Test results are presented on the build pipeline, ensuring that team members follow the necessary guidelines. Code coverage guarantees that testing is an open process for team members, just like code review does.

Better project management data support

Each operation is packaged as a Jenkins task for project management. Both task completion time and success or failure may be determined for each Jenkins job. To monitor success, failure, or time, Jenkins offers REST API or SDK.

Benefits of Jenkins

  • Plugins: One of Jenkins’ key advantages is the extensive library of add-ons that may expand its capability. As of the most recent count, Jenkins has more than 1,800 plugins created by the community, allowing any business to modify or expand the standard capabilities to fit their unique DevOps environment. Jenkins is simple to customise and expand in addition to the plugins to meet the demands of the majority of organizations.
  • Distributed: Jenkins employs a Master-Slave architecture to control distributed builds since one server is sufficient for complex projects. The “Master,” which is the primary server, may then transfer the workload to other “slave” servers, enabling many developments and test environments to operate concurrently. This method might be applied, for instance, to create and test code across many operating platforms.
  • Open-Source: This is undoubtedly a major factor in Jenkins’ appeal to a large audience. Any organization may start using it because it’s free, regardless of its financial limitations. Also simple to install: Jenkins was created as a self-contained Java software, making it compatible with the majority of hardware and operating systems.
  • Community Support: Jenkins currently has a large community supporting it because it is open-source and has been the standard CI tool for many years. Jenkins’ popularity is increased by the ease with which tutorials and other materials can be found to make the most of it.

Limitations of Jenkins

  • Jenkins has a large collection of plug-ins, however, occasionally it appears like the developer team is not keeping them up to date. At this point, whether or not the plug-ins you intend to employ are receiving frequent updates becomes crucial.
  • Many plug-ins have issues with the updating process. It is dependent on plug-ins; oftentimes, even the most basic products are impossible to obtain without them.
  • Jenkins installation and configuration take a long time to complete.
  • When there are too many tasks to be completed, managing the Jenkins dashboard might be challenging. Only the manager will have access to changes made by a developer; the other developers on the team will not be able to see them. It makes tracking challenging in complicated undertakings.
  • The continuous integration process becomes unstable when the parameters are altered. The developer must step in when the integration stops working.

Jenkins: Installation and Setup

Jenkins cannot be configured on Windows without first installing OpenJDK. Jenkins only supports JDK8 as of right now. Jenkins can be set up after Java has begun running.

1. Get the most recent Jenkins package for Windows here.

2. After downloading, it will launch a tutorial on your computer screen. To launch the Jenkins installation, click “Next.”

3. If you wish to install your Jenkins in a different folder, click the “Change…” option.

By selecting the “Next” button in this example, I’ll keep things straightforward and go with the default selection.

4. Type your service login information.

The second choice, “Run service as local or domain user,” is advised since it is safer.

You must supply the domain login and password in order to begin the Jenkins service using this option.

The “Next” button will become active when you click the “Test Credentials” button to verify your domain credentials.

Once it does, click on the “Next” button.

5. Type in the port where Jenkins will operate.

To check if the port is free, click the “Test Port” button.

6. Click the “Next” button after selecting the Java home directory.

7. Choose any additional services that must be deployed with Jenkins and press the “Next” button.

Install Jenkins on Windows

8. To begin the installation procedure, click the “Install” option.

9. The installation will proceed accordingly.

10. Click “Finish” to finish the installation procedure when finished.

After the installation procedure is finished, you must complete a few fast tasks before utilising Jenkins on Windows.

Unlock Jenkins For Windows

11. You will be taken to a local Jenkins page immediately, or you may type http://localhost:8080 into a browser.

12. Copy the password from the initialAdminPassword file to unlock Jenkins.

You should be able to locate this file within the Jenkins installation directory (set at step 3 in Jenkins installation).

You should look there if a custom route was specified.

The initialAdminPassword file’s content should be copied and pasted into the Administrator password box. 

Click the Continue button after that.

13. Depending on your needs, you can install either the recommended plugins or a subset of them.

We will only install the plugins that the Jenkins community recommends as being most helpful in order to keep things simple.

14. Await the completion of the plugin installation.

15. The following action you need to take is to make an Admin user for Jenkins.

Then click Save and Continue after entering your information.

16. To finish installing Jenkins, click Save and Finish.

17. To launch Jenkins, click the “Start using Jenkins” button now.

18. This is the default Jenkins page, to wrap things up.

You can now begin creating your CI/CD pipeline because Jenkins is up and running on Windows.

What Is a Jenkins Pipeline?

Jenkins cannot be operated without pipelines. A pipeline is a series of operations that the Jenkins server will carry out in order to finish the essential CI/CD process tasks. A pipeline is a group of jobs (or events) connected in a certain order in the context of Jenkins. It is a group of plugins that enables Jenkins to build and include Continuous Delivery pipelines.

A user-created continuous delivery pipeline model is the Jenkins pipeline. It has a number of plugins that help at various phases, from user-facing delivery to version control. This is significant since all software modifications and commits must pass a rigorous process before being deployed. Automated construction, multi-step testing, and deployment processes make up the method’s three steps.

In Jenkins, there are two ways to build pipelines


1. Explicitly specify the pipeline using the user interface.

2. Utilise the pipeline as code methodology to produce a Jenkins file.

Using terminology that is compatible with Groovy, a text file that describes the pipeline process is provided. Here are the crucial terms to comprehend before building a Jenkins pipeline

1. Multi-branch Pipeline

To facilitate branch administration, different branches are automatically categorized. When a new branch is pushed to a source code repository, Jenkins automatically creates a new project.

2. Archived Jenkins Pipeline

Since the file archive is safe, you may clean up your workstation and carry out more builds. Take the jar/HTML/js file, for instance, which is essential for deployment. Following another build, your file is changed or removed.

3. Pipeline velocity

This is essential if your pipeline saves large files or intricate data to script variables. Jenkins features a “Speed/Durability” label that lets you execute steps as well as keep variables in scope for later use.

Conclusion

In Continuous Integration, the program is immediately created and tested following a code commit. Jenkins is used in a software project to coordinate a series of tasks for Continuous Integration.

Before Jenkins, all developers would commit their code at the same time after finishing their allocated coding jobs. The build is afterward distributed and tested. As soon as a developer contributes code, Jenkins builds and tests the code. Throughout the day, Jenkins will create and test code several times.

The fact that Jenkins is run by a community that organises open meetings and solicits public opinion for the creation of Jenkins projects is one of its strongest advantages. The major drawback of Jenkins is that, in comparison to modern UI trends, its interface is outdated and unfriendly.

Aliya Rahmani
/
September 21, 2022