0% found this document useful (0 votes)
2 views79 pages

DevOps - Unit - 3.pptx

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 79

UNIT- 3

Build Automation – Continuous Integration(CI)


• What is CI , Why CI is Required ,CI tools
• Introduction to Jenkins (With Architecture)
• Jenkins master slave architecture
• PIPELINE BASICS – Jenkins Master, Node, Agent, and Executor,
Freestyle Projects & Pipelines
• Jenkins Pipelines
• Jenkins for Continuous Integration
• Create and Manage Builds
• User Management in Jenkins
• Schedule Builds
• Launch Builds on Slave Nodes.
What is CI ?
• Continuous integration is a DevOps software development
practice where developers regularly merge their code
changes into a central repository, after which automated
builds and tests are run.
• Continuous integration most often refers to the build or
integration stage of the software release process and
entails both an automation component (e.g. a CI or build
service) and a cultural component (e.g. learning to
integrate frequently).
• The key goals of continuous integration are to find and
address bugs quicker, improve software quality, and
reduce the time it takes to validate and release new
software updates.
Continuous Integration
Why is Continuous Integration Needed?

• In the past, developers on a team might work in isolation


for an extended period of time and only merge their
changes to the master branch once their work was
completed.

• This made merging code changes difficult and


time-consuming, and also resulted in bugs accumulating
for a long time without correction.

• These factors made it harder to deliver updates to


customers quickly.
How does Continuous Integration Work?
• With continuous integration, developers frequently
commit to a shared repository using a version control
system such as Git.
• Prior to each commit, developers may choose to run local
unit tests on their code as an extra verification layer
before integrating.
• A continuous integration service automatically builds and
runs unit tests on the new code changes to immediately
surface any errors.
CI Tools
1. Concourse is a continuous open-source integration and delivery tool that automates
the application and builds tasks efficiently. It was built on the Pivotal Platform in 2014
and was designed to be versatile and safe.

2. Buddy is another CI/CD tool used to build, test, and develop the software code. Buddy
was mainly designed for working on codes that are part of the Bitbucket and GitHub
repositories.

3. Apache Gump is written in Python. It builds and compiles software code against the
latest versions of projects.

4. Buildbot is an open-source CI tool that automates software integration, build and


testing processes. At its core, Buildbot is a job scheduling system: it queues jobs,
executes the jobs when the required resources are available, and reports the results.

5. Bamboo is a CI tool developed by Atlassian. Bamboo is available in two versions,


cloud and server. For the cloud version, Atlassian offers a hosting service with the help
of an Amazon EC2 account. For the server version, self-hosting needs to be done.

6. CircleCI is a CI tool hosted only on GitHub. It supports several languages, including


Java, Python, Ruby/Rails, Node.js, PHP, Skala and Haskell.
7. Draco.NET is a Windows service application created to enable Continuous
Integration for DevOps.

8. GitLab CI is hosted on the free hosting service GitLab.com, and it offers a Git
repository management function with features such as access control, bug
tracking, and code reviewing.

9. Go CD is a CI developed by the company ThoughtWorks. It is available for


Windows, OSX, and Linux operating systems.

10. Jenkins is a cross-platform open-source CI tool written in Java. It offers


configuration through both the GUI interface and the console commands.

11. Travis CI is an open-source CI service free for all open source projects hosted
on GitHub.

12. TeamCity is a Java-based sophisticated CI tool offered by JetBrains. It supports


Java, Net and Ruby platforms. It also offers integration with several IDEs
including, Eclipse, IntelliJ IDEA and Visual Studio.
What is Jenkins?
• Jenkins is an open-source automation tool written in Java with
plugins built for Continuous Integration purposes.

• Jenkins is used to build and test your software projects continuously


making it easier for developers to integrate changes to the project,
and making it easier for users to obtain a fresh build.

• It also allows you to continuously deliver your software by


integrating with a large number of testing and deployment
technologies.
Jenkins is commonly used for ......
• Continuous Integration for application and infrastructure
code.

• Continuously deliver pipeline to deploy the application to


different environments using Jenkins pipeline as code.

• Infrastructure component deployment and management.

• Run batch operations using Jenkins jobs.

• Run operations like backups, cleanups, remote script


execution, event triggers, etc.
As per the Developer Ecosystem Report, 54% of the developers use
Jenkins for CI/CD.
Jenkins Architecture
The following diagram shows the overall architecture of Jenkins
and the connectivity workflow..
Jenkins Jobs
• A job is a collection of steps that you can use to build your source
code, test your code, run a shell script, run an Ansible role in a
remote host or execute a terraform play, etc.
• We normally call it a Jenkins pipeline.

If you
translate
the steps
to a
Jenkins
pipeline
job, it
looks like
• Jenkins Plugins
• Plugins are the primary means of enhancing the functionality of a Jenkins
environment to suit organization- or user-specific needs.

• There are over a thousand different plugins which can be installed on a


Jenkins controller and to integrate various build tools, cloud providers,
analysis tools, and much more.

• Plugins can be automatically downloaded, with their dependencies, from


the Update Center.

• The Update Center is a service operated by the Jenkins project which


provides an inventory of open source plugins which have been developed
and maintained by various members of the Jenkins community.

• Ex for Plugins : Docker Plugin for Jenkins,Jira Plugin,Slack Notification


Plugin,Maven Plugin, Amazon EC2 Plugin, JUnit Plugin,Pipeline Plugin,
Mailer Plugin ,Green Balls Plugin.
• Plugins are official and community-developed modules that you can
install on your Jenkins server.
• It helps you with more functionalities that are not natively available
in Jenkins.
• For example, if you want to upload a file to s3 bucket from Jenkins,
you can install an AWS Jenkins plugin and use the abstracted plugin
functionalities to upload the file rather than writing your own logic
in AWS CLI.
• The plugin takes care of error and exception handling.
• Here is an example, of s3 file upload functionality provided by
the AWS Steps plugin.

• You can install/upgrade all the available plugins from the Jenkins
dashbaord itselft. For corporate net
Following are the key components in Jenkins

• Jenkins Master Node


• Jenkins Agent Nodes/Clouds
• Jenkins Web Interface
Jenkins Master (Server)

• Jenkins’s server or master node holds all key configurations.


• Jenkins master server is like a control server that orchestrates all the
workflow defined in the pipelines. For example, scheduling a job,
monitoring the jobs, etc.
Key Jenkins master components
Jenkins Jobs
• A Jenkins job is a sequential set of tasks that a user
defines.
• For example, a job can fetch source code from version
control, compile the code, run unit tests, and more.
• Note that in Jenkins, the term “job” is synonymous with
“stage”.
Jenkins Agent
• Jenkins agents are the worker nodes that actually execute all the
steps mentioned in a Job.
• When you create a Jenkins job, you have to assign an agent to it.
• Every agent has a label as a unique identifier.

• When you trigger a Jenkins job from the master, the actual
execution happens on the agent node that is configured in the job.
• You can run jobs in the Jenkins server without a Jenkins agent. In
this case, master nodes acts as the agent.
• However, the recommended approach is to have a Jenkins
master-agent setup for different job requirements so that you don’t
end up corrupting the Jenkins server for any system-wide
configuration changes required for a job.
• You can have any number of Jenkins agents attached to a master
with a combination of Windows, Linux servers, and even containers
as build agents.
• Also, you can restrict jobs to run on specific agents, depending on
the use case.
• For example, if you have an agent with java 8 configurations, you
can assign this agent for jobs that require Java 8 environment.
• There is no single standard for using the agents.
• You can set up a workflow and strategy based on your project
needs.
• Jenkins Case Study
• Bosch (Jenkins CloudBees – to Improve efficiency – 3 day build
process reduced to less than 3 hours)
Jenkins Master-agent Connectivity
• You can connect a Jenkins master and agent in two ways
Using the SSH method: Uses the ssh protocol to connect to the agent.
• The connection gets initiated from the Jenkins master.
• Their should be connectivity over port 22 between master and agent.

Using the JNLP method: Uses java JNLP protocol (Java Network
Launch Protocol).
• In this method, a java agent gets initiated from the agent with Jenkins
master details.
• For this, the master nodes firewall should allow connectivity on
specified JNLP port.
• Typically the port assigned will be 50000. This value is configurable.
Jenkins Credentials
• When you set up Jenkins pipelines, there are scenarios where it
needs to connect to a cloud account, a server, a database, or an API
endpoint using secrets.
• In Jenkins, you can save different types of secrets as a credential.
1. Secret text
2. Username & password
3. SSH keys
• All credentials are encrypted (AES) by Jenkins.
• The secrets are stored in $JENKINS_HOME/secrets/ directory.
• It is very important to secure this directory and exclude it from
Jenkins backups.
• Jenkins Nodes/Clouds
• You can configure multiple agent nodes (Linux/Windows) or clouds
(docker, kubernetes) for executing Jenkins jobs.
Jenkins Global Settings (Configure System)
• Under Jenkins global configuration, you have all the configurations
of installed plugins and native Jenkins global configurations.
• Also, you can configure global environment variables under this
section.
• For example, you can store the tools (Nexus(store, distribute, and
retrieve build artifacts whenever it's required), Sonarqube(an
open-source tool for ongoing code quality inspection), etc) URLs as
global environment variables and use them in the pipeline.
• This way it is easier to make URL changes that get reflected in all
the Jenkins jobs.
• Jenkins Logs
• Provides logging information on all Jenkins server actions including
job logs, plugin logs,
There are two types of Jenkins agents
Agent Nodes
• These are servers (Windows/Linux) that will be configured as static
agents. These agents will be up and running all the time and stay
connected to the Jenkins server.
Agent Clouds:
• Jenkins Cloud agent is a concept of having dynamic agents.
• Means, whenever you trigger a job, a agent gets deployed as a
VM/container on demand and gets deleted once the job is
completed.
• This method saves money in terms of infra cost when you have a
huge Jenkins ecosystem and continuous builds.
Jenkins Data

• All the Jenkins data gets stored in the following folder


location.

• Data includes all jobs config files, plugins, configs,


secrets, node information, etc.
• It makes Jenkins migration very easy as compared to
other tools.
• It is essential to back up the Jenkins data folder every day.

• For some reason, if your Jenkins server data gets corrupt,


you can restore the whole Jenkins with the data backup.
Jenkins Web Interface
• Jenkins 2.0 introduced a very intuitive web interface called “Jenkins Blue
Ocean“. It has a good visual representation of all the pipelines.
The following image shows a high-level view of different types of agents
and connectivity types.
Jenkins master slave architecture

• Jenkins uses a Master-Slave architecture to manage distributed


builds. In this architecture, Master and Slave communicate through
TCP/IP protocol.
• 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.
How Jenkins Master and Slave Architecture works?
• Now let us look at an example in which we use Jenkins for testing
in different environments like Ubuntu, MAC, Windows, etc.
The previous image represents the following functions:

• Jenkins checks the Git repository at periodic intervals for


any changes made in the source code.
• Each builds requires a different testing environment
which is not possible for a single Jenkins server.
• In order to perform testing in different environments,
Jenkins uses various Slaves as shown in the previous
diagram.
• Jenkins Master requests these Slaves to perform testing
and to generate test reports.
How to setup Jenkins Master and Slaves?

1. Go to the Manage Jenkins section and scroll down to the section of


Manage Nodes.

2. Click on New Node


3. Give a name for the node, choose the Permanent Agent option, and
click on Ok.

4. Enter the details of the node slave machine.


5. Here no. of executors in nothing but no. of jobs that this slave can
run parallelly.Here we have kept it to 2.
6. The Labels for which the name is entered as “Slave1” is what can
be used to configure jobs to use this slave machine.
7. Select Usage to Use this node as much as possible.
8. For the launch method, we select the option of “Launch agent by
connecting it to the master”.
9. If this option is not visible then go to Jenkins home page ->
Manage Jenkins -> Configure Global Security.
10. Here in the Agents section click on Random and Save it.
11. Now you will find the required option. Enter Custom WorkDir
path as the workspace of your slave node.
12. In Availability select “Keep this agent online as much as
possible”.Click on Save.
• Once you complete the previous steps, the new node machine will
initially be in an offline state but will come online if all the settings
in the previous screen were entered correctly.
• One can at any time make the node slave machine offline if
required.

• Now your slave is up and running, let's execute a job on the slave.
• Take an existing job and run this job on this slave.
• Open the job and click on configure.
• Now here in the General section, click on “Restrict where this
project can be run”.
• Here in Label Expression, enter the name of the slave and save it.
• Now click on Build now and see the output of this job.
• Everything is correct you will see the output as Success.
Jenkins Pipelines
What is a Jenkins pipeline?
• Jenkins Pipeline (or simply "Pipeline") is a suite of plugins which
supports implementing and integrating continuous delivery
pipelines into Jenkins.
• A continuous delivery pipeline is an automated expression of your
process for getting software from version control right through to your
users and customers.
• Every change to your software (committed in source control) goes
through a complex process on its way to being released.
• This process involves building the software in a reliable and
repeatable manner, as well as progressing the built software (called a
"build") through multiple stages of testing and deployment.
• The definition of a Jenkins Pipeline is written into a text file (called
a Jenkinsfile) which in turn can be committed to a project’s source
control repository.
What is Continuous Delivery Pipeline?

• The above diagram represents a continuous delivery pipeline in


Jenkins.
• It contains a collection of states such as build, deploy, test and
release.
• These jobs or events are interlinked with each other.
• Every state has its jobs, which work in a sequence called a
continuous delivery pipeline.
• Continuous delivery lets developers automate testing beyond just
unit tests so they can verify application updates across multiple
dimensions before deploying to customers.
• These tests may include UI testing, load testing, integration testing,
API reliability testing, etc.
• This helps developers more thoroughly validate updates and
pre-emptively discover issues.
JenkinsFile
• Jenkins Pipeline can be defined by a text file called JenkinsFile.
• You can implement pipeline as code using JenkinsFile, and this can
be defined by using a DSL (Domain Specific Language).
• With the help of JenkinsFile, you can write the steps required for
running a Jenkins Pipeline.
The benefits of using JenkinsFile are:
• You can make pipelines automatically for all branches and can
execute pull requests with just one JenkinsFile.
• You can review your code on the pipeline.
• You can review your Jenkins pipeline.
• This is the singular source for your pipeline and can be customized
by multiple users.
A Jenkinsfile can be written using two types of syntax –
Declarative and Scripted.
Declarative:
• Declarative is more recent addition to the Jenkins and provides a more structure
and simple syntax for defining pipelines.
• The code is simplified because declarative syntax is more limited.
• You won’t be able to inject code into the pipeline whenever you want.
• Code validation happens when the pipeline is loaded into the jenkins.
• Errors in the script are detected upfront before running the pipeline.
Example
Scripted:
• Scripted Pipeline is the original pipeline syntax for Jenkins and it is based on
Groovy Scripting Language.
• Scripted Pipeline provides a lot of flexibility and control over the workflow but it
can be more complex and verbose then declarative pipeline.
• It is particularly useful when you have complex build .
• Used for advanced scripting logic within your pipeline.
• Code validation happens during pipeline execution.
• Errors or issues in the script may only be found when the pipeline runs.
Why Use Jenkins Pipeline?
• Jenkins is, fundamentally, an automation engine which supports a
number of automation patterns.
• Pipeline adds a powerful set of automation tools onto Jenkins,
supporting use cases that span from simple continuous integration to
comprehensive CD pipelines.
• By modeling a series of related tasks, users can take advantage of the
many features of Pipeline:
• Code: Pipelines are implemented in code and typically checked into
source control, giving teams the ability to edit, review, and iterate upon
their delivery pipeline.
• Durable: Pipelines can survive both planned and unplanned restarts of
the Jenkins controller.
• Pausable: Pipelines can optionally stop and wait for human input or
approval before continuing the Pipeline run.
• Versatile: Pipelines support complex real-world CD requirements,
including the ability to fork/join, loop, and perform work in parallel.
• Extensible: The Pipeline plugin supports custom extensions to its
DSL and multiple options for integration with other plugins.
Jenkins Pipeline Concepts
• Pipeline: A Pipeline is a user-defined model of a CD pipeline. A
Pipeline’s code defines your entire build process, which typically
includes stages for building an application, testing it and then
delivering it.
• Node: A node is a machine which is part of the Jenkins environment
and is capable of executing a Pipeline.
• Stage: A stage block defines a conceptually distinct subset of tasks
performed through the entire Pipeline (e.g. "Build", "Test" and
"Deploy" stages), which is used by many plugins to visualize or
present Jenkins Pipeline status/progress.
• Step: A single task. Fundamentally, a step tells Jenkins what to do at a
particular point in time (or "step" in the process).
• Agent:An agent is typically a machine, or container, which connects
to a Jenkins controller and executes tasks when directed by the
controller.
Jenkins for Continuous Integration
• Continuous Integration is a process of integrating code
changes from multiple developers in a single project many
times.
• The software is tested immediately after a code commit.
With each code commit, code is built and tested.
• If the test is passed, the build is tested for deployment.
• If the deployment is successful, the code is pushed to
production.
• This commit, build, test, and deploy is a continuous
process and hence the name continuous
integration/deployment.
How does Jenkins work?
• Jenkins is a server-based application and requires a web server like
Apache Tomcat to run on various platforms like Windows, Linux,
macOS, Unix, etc.
• To use Jenkins, you need to create pipelines which are a series of
steps that a Jenkins server will take.
• Jenkins Continuous Integration Pipeline is a powerful instrument that
consists of a set of tools designed to host , monitor , compile and
test code, or code changes, like:
• Continuous Integration Server (Jenkins, Bamboo, CruiseControl,
TeamCity, and others)
• Source Control Tool (e.g., CVS, SVN, GIT, Mercurial, Perforce,
ClearCase and others)
• Build tool (Make, ANT, Maven, Ivy, Gradle, and others)
• Automation testing framework (Selenium, Appium, TestComplete,
UFT, and others)
The flowchart below is an example of one Continuous Delivery scenario
easily modeled in Jenkins Pipeline:
How to Create a New Build Job in Jenkins
Freestyle Project

• Jenkins Freestyle Project is a repeatable build job, script,


or pipeline that contains steps and post-build actions.
• It is an improved job or task that can span multiple
operations.
• It allows you to configure build triggers and offers
project-based security for your Jenkins project.
• It also offers plugins to help you build steps and
post-build actions.
How to Create a New Build Job in Jenkins
Step 1) Login to Jenkins
• To create a Jenkins freestyle job, log on to your Jenkins
dashboard by visiting your Jenkins installation path.
Usually, it will be hosted on localhost
at http://localhost:8080 If you have installed Jenkins in
another path, use the appropriate URL to access your
dashboard as shown in the below Jenkins job creation
example.
Step 2) Create New Item
Click on “New Item” at the top left-hand side of your dashboard.
Step 3) Enter Item details
• Enter the name of the item you want to create. We shall use the “Hello world” for
this demo.
• Select Freestyle project
• Click Ok
Step 4) Enter Project details
• Enter the details of the project you want to test.

Step 5) Enter repository URL


• Under Source Code Management, Enter your repository URL. We have a test
repository located at https://github.com/kriru/firstJava.git
Step 6) Tweak the settings
• Now that you have provided all the details, it’s time to build the code. Tweak the
settings under the build section to build the code at the time you want. You can
even schedule the build to happen periodically, at set times.
• Under build,
1. Click on “Add build step”
2. Click on “Execute Windows batch command” and add the commands you want
to execute during the build process.
• Here, I have added the java commands to compile the java code.
• I have added the following windows commands:
• javac HelloWorld.java
• java HelloWorld
Step 7) Save the project
• When you have entered all the data,
• Click Apply
• Save the project.
Step 8) Build Source code
• Now, in the main screen, Click the Build Now button on the left-hand side to
build the source code.
Step 9) Check the status
• After clicking on Build now, you can see the status of the build you run
under Build History.
Step 10) See the console output
• Click on the build number and then Click on console output to see the status of
the build you run. It should show you a success message, provided you have
followed the setup properly as shown in the below Jenkins create new job
example.

• we have executed a HelloWorld program hosted on GitHub. Jenkin pulls the code
from the remote repository and builds continuously at a frequency you define.
User Management in Jenkins

• Generally, in a large organization, there are multiple, separate teams


to manage and run jobs in Jenkins.
• But managing this crowd of users and assigning roles to them can
prove troublesome.
• By default, Jenkins comes with very basic user creation options.
• You can create multiple users but can only assign the same global
roles and privileges to them.
• This not ideal, especially for a large organization.
• The Role Strategy Plugin enable you to assign different roles and
privileges to different users.
• You will first need to install the plugin in your Jenkins mange
environment.
How to Create/Add a User in Jenkins

Step 1) Login to Jenkins Dashboard


• Login to your Jenkins dashboard by visiting http://localhost:8080/
Step 2) Choose the option
• You will now see options to create and add user in Jenkins and manage current
users.
Step 3) Create a new User
• Under Manage Jenkins, Click Create User
• Enter Jenkins add user details like password, name, email etc.
• Click Create User
Step 4) User is created
• You will see on the dashboard that a new Jenkins create user as per the details
entered.
How to Install Role Strategy Plugin in Jenkins
• There are two methods for installing plugins in Jenkins.
• Installing it through your Jenkins dashboard
• Downloading the plugin from Jenkins website and installing it manually.
Step 1)
• 1. Go to Manage Jenkins
• 2. Click on the Manage Plugins option
Step 2)
• In available section, screen Search for “role”.
• Select Role-based Authorization Strategy plugin
• Click on “Install without restart” (make sure you have an active internet
connection)

Step 3)
• Once the plugin is installed, a “success” status will be displayed.

• Click on Go back to the top page.


• Step 4) Go to Manage Jenkins -> Configure Global Security ->
Under Authorization, select Role Based Strategy. Click on Save.
How to Manage Users and Roles in Jenkins
• Following are the steps on how to manage and assign roles in Jenkins:
• Step 1)
• 1. Go to Manage Jenkins
• 2. Select Manage and Assign Roles
Step 2) Click on Manage Roles to add new roles based on your organization.

Step 3) To create a new role called “developer”,


• Type “developer” under “role”.
• Click on “Add” to create a new role.
• Now, select the Jenkins user permissions you want to assign to the “Developer”
role.
• Click Save
How to Assign Roles in Jenkins
Step 1) Now that you have created roles, let us assign them to specific users.
• Go to Manage Jenkins
• Select Manage and Assign Roles

Step 2) We shall add the new role “developer”


to user “guru99”
• Selector developer role checkbox
• Click Save
Schedule Builds
• How to Schedule a Jenkins Job
• First, let’s look at the Jenkins job scheduling configuration.
• It looks a lot like Linux cron syntax, but you don’t have to be
familiar with command line Linux to figure it out.
• A scheduling entry consists of five whitespace-separated fields.

• You can schedule a job for more than one time by adding more than
one entry.
• Each field can contain an exact value or use a set of special
expressions:
• The familiar asterisk * indicates all valid values. So, a job that runs
every day has a * in the third field.
• A dash separates ranges of values. For example, a job that runs
every hour from 9:00 a.m. to 5:00 p.m. would have 9-17 in the
second field.
• Intervals are specified with a slash /. A job that runs every 15
minutes has H/15 in the first field.
• Note that the H in the first field has a special meaning.
• If you wanted a job to run every 15 minutes, you could configure it
as 0/15, which would make it run at the start of every hour.
• However, if you configure too many jobs this way, you can
overload your Jenkins controller.
• Ultimately, the H tells Jenkins to pick a minute based on a hash of
the job name.
• Finally, you can specify multiple values with a comma. So, a job
that runs Monday, Wednesday, and Friday would have 1,3,5 in the
fifth field.
• Examples : # Every fifteen minutes : H/15 * * * *
# Every ten minutes in the first half of every hour : H(0-29)/10 * * * *
Builds on Slave Nodes
• The machine where we install standard Jenkins will be
our Jenkins master.
• On the slave node machine, we will install a runtime
program called Agent.
• Installing Agent will not be a standard Jenkins install, but
this Agent will run on the JVM.
• It is capable enough to run the subtask or main task of
Jenkins in a dedicated executor.
• We can have any number of Agent nodes or slave nodes.
• Further, we can configure the master node to decide
which task or job should run on which agent and how
many executor agents we can have.
• The communication between master and Jenkins slave
nodes is bi-directional and takes place over TCP/IP.
Distributed Builds
Step by step process to add Jenkins slave nodes
• In a production environment, there are lot and lot
of builds need to run in parallel.
• This is the time Jenkins slave nodes come into the play.
• We can run builds in separate Jenkins slave nodes.
• This will reduce build overhead to the Jenkins master and
we can run build in parallel.
• This step by step guide will help you to add any
flavour of Linux machine as a Jenkins slave node.
Prepare Slave nodes
• Before adding a slave node to the Jenkins master we need
to prepare the node.
• We need to install Java on the slave node.
• Jenkins will install a client program on the slave node.
• To run the client program we need to install the same Java
version we used to install on Jenkins master.
• Here we use this slave node to build Java Maven project.
• Therefore you need to install Maven as well.
• According to your production environment, you need to
install and configure the necessary tool in the slave
node.
• Install OpenJDK 8 on the slave node
# sudo yum install -y java-1.8.0-openjdk
• As mention before, now install apache maven on the slave node.

• Log in to the Jenkins master node and create an ssh key-pair.


• Copy the content and log in to the slave node. Add the
copied content to authorized_keys.
# vim .ssh/authorized_keys
• It will ask to accept the ssh fingerprint, type yes
and enter.
Adding the slave node to the master
• Log in to the Jenkins console via the browser and click
on "Manage Jenkins" and scroll down to the bottom.
• From the list click on "Manage Nodes".
• In the new window click on "New Node".
• Note that ssh user must have read/write access to this
directory path.

• Click on the "Add" button near the credentials field.


• Select the kind as "SSH Username with private key" from
the drop-down.
• Enter the user name of the slave node.
• In the private key field add the Jenkins masters private
key.

• You can find the private key with the below command
# cat /home/centos/.ssh/id_rsa
• Click on add and select the credentials we created
from the drop-down.
• Click on save.
• If you did all the correct slave node will come to live state
within a few seconds.

You might also like