Table of contents
What is Jenkins?
Jenkins is a tool that is used for automation. It is mainly an open-source server that allows all the developers to build, test and deploy software.
It is written in Java and runs on Java only. By using Jenkins we can make a continuous integration of projects(jobs) or end-to-endpoint automation.
Jenkins is a tool that is used for automation, and it is an open-source server that allows all the developers to build, test and deploy software. It works or runs on java as it is written in java. By using Jenkins we can make a continuous integration of projects(jobs) or end-to-endpoint automation.
Jenkins achieves Continuous Integration with the help of plugins. Plugins allow the integration of Various DevOps stages. If you want to integrate a particular tool, you need to install the plugins for that tool. For example Git, Maven 2 project, Amazon EC2, HTML publisher etc.
Why organizations use Jenkins?
Efficiency: Jenkins automates repetitive tasks, freeing up developers' time to focus on writing code and solving problems.
Consistency: It ensures that code is built, tested, and deployed in the same way every time, reducing the chance of human error.
Faster Releases: By automating the build and deployment process, Jenkins helps organizations release new features and updates more quickly.
Early Problem Detection: Continuous integration with Jenkins catches issues early in the development process, making them easier and cheaper to fix.
Collaboration: Jenkins integrates changes from multiple developers seamlessly, improving team collaboration and ensuring everyone works with the latest version of the code.
Advantages of Jenkins?
It is an open-source tool with great community support.
Too easy to install.
It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share it with the community.
It is free of cost.
It is built with Java and hence, it is portable to all the major platforms.
Understanding Jenkins Master-Slave architecture
The Master-Slave Architecture in Jenkins becomes an important concept to know that can enhance the efficiency of our CI/CD processes. This architecture helps us in such a way that if we have multiple processes running on Jenkins, it can easily manage them by distributing the processes to multiple other nodes.
By node, it means it’s the slave. In Master-Slave Architecture, the master is like the boss who manages and controls everything, and slaves are like the workers who do the actual work. Master and Slave interact with each other using TCP/IP protocols.
Master-slave architecture in Jenkins is like a team working on a project. It is mainly used to manage distributed builds.
Why Master-Slave Architecture?
Master-slave architecture helps to distribute large loads and make our process fast and efficient. Here are some more points why we should consider Master-Slave Architecture:
Jenkins Master
Your main Jenkins server is the Master. The Master’s job is to handle:
Scheduling build jobs.
Dispatching builds to the slaves for the actual execution.
Monitor the slaves (possibly taking them online and offline as required).
Recording and presenting the build results.
A Master instance of Jenkins can also execute build jobs directly.
Jenkins Slave
A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:
It hears requests from the Jenkins Master instance.
Slaves can run on a variety of operating systems.
The job of a Slave is to do as they are told to, which involves executing build jobs dispatched by the Master.
You can configure a project to always run on a particular Slave machine or a particular type of Slave machine, or simply let Jenkins pick the next available Slave.
Install Jenkins on Linux (Ubuntu)
- First of all, go to the AWS portal, and create a new instance. As,
· Name: Jenkins-Master
· AMI: ubuntu.
· Instance type: t2.micro (free tier).
· Key pair login: Create > jenkins-master.pem.
· Allow HTTP (Anywhere).
· Allow HTTPS (Anywhere).
Click on Launch Instance, then connect to the EC2 instance and install following packages:
- Update all packages after connecting to instance
# Mandatory step **
# Update all packages
$ sudo apt update
- Installing Jenkins using script
- Install Java(Pre-requisite for Jenkins):
$ sudo apt install fontconfig openjdk-17-jre
- Now, Install Jenkins
Create script called jenkins.sh
and add below commands.
$ sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
$ echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
$ sudo apt-get update -y
$ sudo apt-get install jenkins -y
Then give executable permission to script jenkins.sh
,
$ chmod 700 jenkins.sh
Execute script,
$ ./jenkins.sh
Access Jenkins using UI, Before that allow port 8080
in security group of instance.
Access of Jenkins server should be accessible from OWN IP only initially.
After above step you will get like,
Go to the location which is mentioned in Unlock Jenkins page at system level and copy the Admin password then paste in box.
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
e8e6f212c37742b491de027910dc****
Click on Installed suggested plugins,
Now, create Admin user
Default Jenkins server URL,
Now, Jenkins is ready.
Below is an Welcome page of Jenkins after fresh installation,
How to Achieve Jenkins master-slave architecture?
For detailed configuration, I have already created blog.
kindly visit Blog.
Create a freestyle pipeline to print "Hello World!!"
Create new Job
Give name to Job : DemoFreestyle
Select "Freestyle Project"
Click on "OK".
After this, you will reach a page where you have different options(like build, build triggers, source code management) that help you manage your job.
- Give description of Job.
Source Code Management
Select "None", cause we are not going to fetch code from any repository.
After this, if you want to give some triggers then you can choose accordingly even Jenkins provides us scheduled triggers. And you can choose to build an environment also accordingly. But, here we are making a simple job, so we are not using any triggers and build environment options.
- Build Steps, Select "Execute Shell".
- Execute shell command to print "Hello World!!".
- Click "Save" button.
Now, finally Build job.
Verify output at "Console output" of Build.
Connect With Me
Follow me for more amazing content :)