Table of contents
What is Jenkins?
Jenkins
is a Java-based open-source automation platform with plugins designed for continuous integration or continuous delivery. It is used to continually create and test software projects, making it easier for developers and DevOps engineers to integrate changes to the project and for consumers to get a new build.
Plugins
are the primary means of enhancing the functionality of a Jenkins environment to suit organization or user-specific needs.
Jenkins
uses master-slave
architecture. Jenkins Master
will distribute its workloads to the slave and Jenkins Slaves
work on the basis of requests received from the Jenkins Master.
Features of Jenkins
Jenkins offers many attractive features for developers:
Easy Installation: Jenkins is a platform-agnostic, self-contained Java-based program, ready to run with packages for Windows, Mac OS, and Unix-like operating systems.
Easy Configuration: Jenkins is easily set up and configured using its web interface, featuring error checks and a built-in help function.
Available Plugins: There are hundreds of plugins available in the Update Center, integrating with every tool in the CI and CD toolchain.
Extensible: Jenkins can be extended by means of its plugin architecture, providing nearly endless possibilities for what it can do.
Easy Distribution: Jenkins can easily distribute work across multiple machines for faster builds, tests, and deployments across multiple platforms.
Free Open Source: Jenkins is an open-source resource backed by heavy community support.
What is Pipeline in Jenkins?
A pipeline
is a concept that introduces a series of events or tasks that are connected in a sequence to make quick software releases.
For example, there is a task, that task has got five different stages, and each stage has got several steps. All the steps in phase one must be completed, to mark the latter stage to be complete.
The Pipeline
is responsible for building codes, running tests, and deploying new software versions. The Pipeline
executes the job in a defined manner by first coding it and then structuring it inside several blocks that may include several steps or tasks.
What is CI/CD in Jenkins?
The term “CI/CD” refers to the Continuous Integration/Continuous Delivery.
Continuous Integration (CI)
: is a practice that integrates code changes from multiple developers into a shared repository. It can automatically trigger builds and tests whenever changes are pushed to the repository, enabling quick feedback on code quality and preventing integration issues. It only doesn't eliminate bugs but also helps in finding and removing them quickly.
Continuous Delivery (CD)
: is the phase where the changes are made in the code before deploying. Jenkins enables the continuous delivery of software by automating the deployment process. It can deploy applications to various environments, such as development, staging, and production, based on predefined configurations. This helps ensure consistent and reliable deployments.
However, you will see in most of the places "CD" is also refer to as Continuous Deployment
. So, Continuous Deployment
automates the release process, deploying changes to production automatically once tests pass, While Continuous Delivery
focuses on ensuring software is always release-ready with manual approval.
Use Cases of Jenkins
Some of the use cases of Jenkins including CI/CD are: -
Automated Testing
: Jenkins can integrate with different testing frameworks, allowing automated tests to be executed as part of the build process. It helps identify bugs and issues early in the development cycle, ensuring the quality of the software.Deployment Orchestration
: Jenkins can be used to automate the deployment of applications to different servers and environments. It streamlines the process of deploying and managing software across multiple servers or cloud platforms.Scheduled Jobs and Batch Processing
: Jenkins can be configured to perform routine tasks at scheduled intervals, such as running backups, generating reports, or executing batch jobs. This helps automate repetitive tasks and frees up developers’ time for more critical activities.
What is a Project in Jenkins?
Jenkins uses projects
(also known as "jobs") to perform its work. Projects
are defined and run by Jenkins users. Jenkins offers several different types of projects, including:
Pipeline
Multibranch Pipeline
Organization folders
Freestyle
Multi-configuration (matrix)
Maven
External job
Different Types of Jenkins Projects:
Freestyle Project
: This is the most basic project type in Jenkins. It provides a lot of flexibility and allows users to define build steps and configurations based on their specific requirements. It is suitable for simple or custom-build processes.Pipeline Project
: Jenkins Pipeline is a powerful and extensible way to define the build, test, and deployment workflows as code. It uses a domain-specific language (DSL) or a declarative syntax to define the entire build pipeline, including stages, steps, and conditions. Pipeline projects are highly versatile and recommended for complex build processes and CD workflows.Multibranch Pipeline
: This type of project is useful when you have multiple branches in your source code repository, and you want to build and test each branch separately. Jenkins automatically detects new branches and creates build pipelines for them, providing visibility into the status of different branches.
Benefits and Use Cases of Each Project Type
1. Freestyle Project:
Flexibility
: Freestyle projects provide the highest level of flexibility in Jenkins. You have full control over the configuration and build steps, allowing you to customize the project to meet your specific requirements.Easy setup
: Freestyle projects are relatively simple to set up, making them ideal for small projects or quick automation tasks.User-friendly interface
: The user interface for configuring freestyle projects is intuitive and straightforward, making it easy for beginners to get started.
2. Pipeline Project:
Continuous Delivery as code
: Jenkins Pipeline allows you to define your entire build, test, and deployment workflows as code. This provides several benefits:Version control
: Pipelines can be stored in a version control system, enabling easy collaboration, review, and rollback of changes.Reusability
: Pipeline code can be shared and reused across multiple projects, ensuring consistency and reducing duplication.Scalability
: Pipelines are highly scalable and can handle complex workflows with multiple stages, parallel execution, and conditional logic.Visualization and monitoring
: Pipeline projects provide a visual representation of the entire workflow, making it easy to track the progress of builds and deployments. Jenkins provides detailed logs and reports, helping identify issues and bottlenecks in the pipeline.
3. Multibranch Pipeline:
Independent branch testing
: With multibranch pipelines, each branch in your source code repository can have its own build and test pipeline. This allows for independent testing and validation of changes made in different branches, ensuring branch-specific issues are caught early.Automatic branch detection
: Jenkins automatically detects new branches and creates build pipelines for them, reducing the manual effort required to set up pipelines for each branch.Streamlined management
: Multibranch pipelines provide a consolidated view of the build status across all branches, making it easy to monitor and manage multiple branches simultaneously.
Installation of Jenkins
Step 1: Update Packages: Run the following command to update the package lists for upgrades and new installations:
sudo apt-get update
Step 2: So, before installing Jenkins, firstly we have to install Java on our machine.
Below is the command to install Java: -
sudo apt install openjdk-11-jre
Step 3: Check whether the java is installed or not.
java --version
Step 4: Now, moving ahead with the installation of Jenkins, below is the command to install Jenkins on your machine. Add the Jenkins repository key to the system using the following commands:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
Step 5: Then add the Jenkins repository to the package sources:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
Step 6: Update the package lists and install Jenkins:
sudo apt-get update
sudo apt-get install jenkins
Step 7: Start Jenkins: The Jenkins service should start automatically after installation. If it's not running, start it with the following command:
sudo systemctl start jenkins
Step 8: Check whether Jenkins is active or not
systemctl status jenkins
Step 9: Jenkins
runs on port 8080
. So, go to your instance and add this port to the security group.
Step 10: Go to the Security Group:
Step 11: Click on "Edit Inbound Rules":
Step 12: Now add a rule and save it.
Step 13: After adding the port in inbound rule
, Access Jenkins Web Interface: Open a web browser and enter the public IP address or DNS name of your EC2 instance followed by the Jenkins port (e.g. http://<your_public_ip>:8080). You should see the Jenkins setup wizard.
You can find the Admin password on the location given in the above snapshot.
Setting up Jenkins
After entering your password, you can now customize your Jenkins.
After installing the plugins, it will ask you to create the first admin user. Fill in the details.
Your Jenkins is now readyyyyy!!!✨
After your Jenkins is ready, You will find the below Jenkins Dashboard.
Freestyle Project Example
We will create a simple freestyle project pipeline.
Step 1: Click on "New Item"
Step 2: Enter an item name and choose Freestyle mode and Click on "OK".
Step 3: Configure your pipeline as in this case we are simply executing the shell command. So, we will directly go to "Build Steps" and leave the remaining as it is.
So, we have added a simple shell command i.e., echo "Hello World!!" in build steps and save the configuration.
Step 4: Click on "Build Now".
Step 5: After you click on "Build Now", you can see in Build History one pipeline gets triggered.
Step 6: You can find the output or logs of the pipeline in "Console Output". As you can see the command has been successfully executed. So, the pipeline has "Green Tick"
So, this was the simple freestyle project pipeline.
Conclusion
In conclusion, Jenkins
and pipelines
play crucial roles in modern software development, enabling efficient and automated workflows.
Jenkins
, as a widely-used open-source automation server, provides a robust platform for continuous integration and continuous delivery (CI/CD). The flexibility and extensibility of Jenkins make it a valuable tool for organizations aiming to achieve agility and automation in their software development lifecycle.
Pipelines
in Jenkins serve as a structured and programmable way to define, orchestrate, and automate the software delivery process.
Together, Jenkins and pipelines
empower development teams to streamline their build, test, and deployment processes, fostering faster and more reliable software delivery.
*👆The information presented above is based on my interpretation. Suggestions are always welcome.*😊
~Smriti Sharma✌