Jenkins
Jenkins
Answer: Jenkins is a free open source Continuous Integration tool and automation server to
monitor continuous integration and delivery. It is written in Java.
It is known as an automated Continuous Delivery tool that helps to build and test the software
system with easy integration of changes to the system. Jenkins follows Groovy Scripting.
Also, it enables developers to continuously check in their code and also analyze the post-build
actions. The automation testers can use to run their tests as soon as the new code is added or
code is modified.
Whenever the programmer/developer makes any change to the current code, then it
automatically
gets integrated with the system running on the tester’s machine and makes the testing task
easy and speedy for the system testers.
(It involves keeping the latest copy of the source code at a commonly shared hub where all the
developers can check to fetch out the latest change in order to avoid conflict.)
Continuous Delivery:
}
In the above syntax, the node is a part of the Jenkins distributed mode architecture, where
there are two types of node, Master which handle all the tasks in the development
environment and the Agent is being used to handle multiple tasks individually.
/* Declarative Pipeline */
}
Blocks must contain Sections, Directives, steps or assignments.
pipeline {
agent any
stages {
stage(‘Build’) {
steps {
// Statements…
stage (‘Test’) {
steps {
// Statements…
scm:
git:
url: ssh://Jenkins.org/eloc.git
Q #20) How to make sure that your project build does not break in Jenkins?
Answer: You need to follow the below-mentioned steps to make sure that the Project build
does not break:
1. Clean and successful installation of Jenkins on your local machine with all unit
tests.
2. All code changes are reflected successfully.
3. Checking for repository synchronization to make sure that all the differences and
changes related to config and other settings are saved in the repository.
The below table enlists the differences between Maven, Ant, and Jenkins in a comparative
way:
Maven Ant Jenkins
Defines how the software is built Drives build process. Automates the software development process
and describes the software with Continuous Integration and facilitates
dependencies. Continuous Deliver.
Supports projects written in C#, Supports projects written in C Supports version control tools like Git,
Ruby. and C++. AccuRev.
Maven Ant Jenkins
Executes Unit Tests as a part of the Supports single file execution Can execute Apache Ant and Apache Maven.
normal build cycle. introduced with Java II.
Step 2: Click on the New Item that is shown in the left panel of the page.
Step 3: Click on the Freestyle Project from the given list on the upcoming page and specify
the item name in the text box.
Step 4: Add the URL to the Git Repository.
Step 5: Go to the Build section and click on the Add build step => Execute Windows batch
command.
Step 6: Enter the command in the command window as shown below.
Step 7: After saving all the settings and changes click on Build Now.
Step 8: To see the status of the build click on Console Output.
Q #25) What are the two components (pre-requisites) that Jenkins is mainly integrated with?
Answer: Jenkins integrates with:
1. Build tools/ Build working script like Maven script.
2. Version control system/Accessible source code repository like Git repository.
You can maintain a separate backfile and copy it whenever you need the same. If you want to
copy the Jenkins job, then you can do so by simply replicating the job directory.
Q #29) What is the use of Backup Plugin in Jenkins? How to use it?
Answer: Jenkins Backup Plugin is used to back up the critical configurations and settings in
order to use them in the future in case of any failure or as per the need of time.
The following steps are followed to back up your settings by using the Backup Plugin.
Step 1: Go to the Jenkins Dashboard and click on Manage Jenkins.
Step 4: Once you choose the available option, it will start installing.
Step 5: Once it is installed the following screen will appear, from there choose Settings.
Step 6: Enter the necessary details like backup directory along with other options as shown on
the below screen and save the settings. The backup will be saved to the specified Backup
Directory.
Step 7: Go to the previous page to test whether the backup is happening or not by clicking
on Backup Now as shown in the below image.
Step 8: At last, you can check the Backup Directory specified in the ThinBackup Settings. (Step
6) to check the whole backup
Q #31) What is the solution if you find a broken build for your project?
Answer: To resolve the broken build follow the below-mentioned steps:
Open console output for the build and check if any file change has missed.
OR
Clean and update your local workspace to replicate the problem on the local
system and try to resolve it (In case you couldn’t find out the issue in the console
output).
agent
stages {
agent
steps {
stage('Test') {
agent
steps {
These are some of the frequently asked questions in the Jenkins interview, you can practice
them as part of your preparation for the interview.
We advise you to practice some Jenkins scripts before attending an interview. Also for detailed
information and processes in Jenkins please check Jenkins.
Just commit changes to the SCR (Source Code Repository) and Jenkins can automate
the rest of the process for you with the help of plugins. So that makes it a very
important tool in DevOps Certification Training. There is a high possibility that you
encounter many Jenkins questions if you go for a DevOps job interview. Below are
the most frequently asked Jenkins interview questions. I have collected these
questions after doing a lot of research and after discussing with some DevOps
experts who are directly involved in the hiring process. Curious to know more
about Jenkins check out this Jenkins blog series.
Explore Curriculum
In this blog we have covered roughly 50+ questions and we have divided them into
3 categories –
Basic Questions
Intermediate Questions
Advanced Questions
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.
I will suggest you include the following benefits of Jenkins if you can recall any other
benefit apart from the below-mentioned points you can include that as well.
You can just say Hudson was the earlier name and version of current Jenkins. After
some issues, they renamed the project from Hudson to Jenkins.
Maven 2 project
Git
Amazon EC2
HTML publisher
Copy artifact
Join
Green Balls
These Plugins I feel are the most useful plugins, if you want to include any other
Plugin that is not mentioned above, you can add that as well, but make sure you
first mention the above-stated plugins and then add your own.
1. Install Java Version 8 – Jenkins is a Java based application, hence Java is a
must.
2. Install Apache Tomcat Version 9 – Tomcat is essential to deploy Jenkins war
file.
3. Download Jenkins war File – This war is must to install Jenkins.
4. Deploy Jenkins war File – You deploy Jenkins war file using Tomcat to run
Jenkins.
5. Install Suggested Plugins – Install a list of plugins suggested by Jenkins.
Once the installation is complete, you will be able to see the Jenkins dashboard.
Q9. What are the two components that you can integrate Jenkins with?
If you have anything else in your mind then mention that as well but make sure you
include the above two components in your answer.
Maven is a build management tool. It uses a simple pom.xml to configure all the
dependencies needed to build, test and run the code. Maven manages the full
lifecycle of a test project. Once integrated with Jenkins, the maven Webdriver will
build the project and execute all tests efficiently.
Q11. Mention what are the commands you can use to start Jenkins manually.
For this answer I will suggest you go with the below-mentioned flow:
To start Jenkins manually open Console/Command line, then go to your Jenkins
installation directory. Over there you can use the below commands:
Here are some of the Source Code Management tools supported by Jenkins:
AccuRev
CVS
Subversion
Git
Mercurial
Perforce
Clearcase
RTC
Parameters are supported by Agent section and they are used to support various
use-cases pipelines. Parameters are defined at the top-level of the pipeline or
inside an individual stage directive.
Groovy from Apache is a language designed for the Java platform. It is the native
scripting language for Jenkins. Groovy-based plugins enhance Jenkins with great
interfaces and build reports that are of dynamic and consistent nature.
Intermediate Questions
If you want to clone a Git repository via Jenkins, you have to enter the e-mail and
user name for your Jenkins system. Switch into your job directory and execute the
“git config” command for that.
My approach to this answer will be to first mention how to create Jenkins job.
Go to Jenkins top page, select “New Job”, then choose “Build a free-style software
project”.
Optional SCM, such as CVS or Subversion where your source code resides.
Optional triggers to control when Jenkins will perform builds.
Some sort of build script that performs the build (ant, maven, shell script,
batch file, etc.) where the real work happens.
Optional steps to collect information out of the build, such as archiving the
artifacts and/or recording javadoc and test results.
Optional steps to notify other people/systems with the build result, such as
sending e-mails, IMs, updating issue tracker, etc..
The way I secure Jenkins is mentioned below if you have any other way to do it than
mention that:
Stop Jenkins.
Copy the custom HPI to $Jenkins_Home/plugins.
Delete the previously expanded plugin directory.
Make an empty file called <plugin>.hpi.pinned.
Start Jenkins.
Q21. What you do when you see a broken build for your project in Jenkins?
There can be multiple answers to this question I will approach this task in the
following way:
I will open the console output for the broken build and try to see if any file changes
were missed. If I am unable to find the issue that way, then I will clean and update
my local workspace to replicate the problem on my local and try to solve it.
Q22. What are the various ways in which build can be scheduled in Jenkins?
Pipeline plugin is used in Jenkins for making the Jenkins Pipeline, which gives us the
view of stages or tasks to perform one after the other in the pipeline form. It
models a series of related tasks. Pipelines help the teams to review, edit and iterate
upon the tasks. Pipelines are durable and it can optionally stop and wait for human
approval as well to start the next task. A pipeline is extensible and can perform
work in parallel. It supports complex CD requirements.
Post-section: If we have to add some notification and to perform other tasks at the
end of a pipeline, post-section will definitely run at the end of every pipeline’s
execution.
Jenkinsfile: The text file where all the definitions of pipelines are defined is called
Jenkinsfile. It is being checked in the source control repository.
Q25. Do you know about cloud computing? How can Jenkins fit into a cloud computing
environment? Explain with an example.
Let us take the example of AWS cloud service. Cloud computing services use the
CI/CD model so that they can push their work to the customers and constantly
receive feedback. Jenkins is used to automating the CI/CD pipelines. For example, a
lot of Jenkins plugins are available for many of the AWS services like Amazon EC2
and ECS.
Yes, this can be done easily. Automated tests can be run through tools like
Selenium or maven. Developers can schedule the test runs. Jenkins displays the test
results and sends a report to the developers.
Q28. Let us say, you have a pipeline. The first job was successful, but the second failed.
What should you do next?
You just need to restart the pipeline from the point where it failed by doing ‘restart
from stage’.
All the settings, logs and configurations are stored in the JENKINS_HOME directory.
This is a helpful plugin that backs up all the critical settings and configurations to be
used in the future. This is useful in cases when there is a failure so that we don’t
lose the settings.
Q31. What is a trigger? Give an example of how the repository is polled when a new
commit is detected.
Triggers are used to define when and how pipelines should be executed.
When Jenkins is integrated with an SCM tool, for example, Git, the repository can be
polled every time there is a commit.
The Git plugin should be first installed and set up.
After this, you can build a trigger that specifies when a new build should be
started. For example, you can create a job that polls the repository and
triggers a build when a change is committed.
A build can take several input parameters to execute. For example, if you have
multiple test suites, but you want to run only one. You can set a parameter so that
you are able to decide which one should be run. To have parameters in a job, you
need to specify the same while defining the parameter. The parameter can be
anything like a string, a file or a custom.
Q33. What are the ways to configure Jenkins node agent to communicate with Jenkins
master?
The default way is to store user data and credentials in an internal database.
Configure Jenkins to use the authentication mechanism defined by the
application server on which it is deployed.
Configure Jenkins to authenticate against LDAP server.
Below are the steps used for working with a third-party tool in Jenkins.
For different third-party tools, the procedure may vary slightly, because of the
difference in configuration settings.
Q37. What syntax does Jenkins use to schedule build job or SVN polling?
Cron syntax is represented using five asterisks each separated by a space. The
syntax is as follows – [minutes] [hours] [day of the month] [month] [day of the
week]. Example, if you want to set up a cron for every Monday at 11.59 pm, it would
be 59 11 * * 1
Q38. What is DevOps and in which stage does Jenkins fit in?
Q39. Do you know any other Continuous Integration tools? How is Jenkins better than any
of those?
There are many other CI tools, and the most prominent ones are –
TeamCity
Bamboo
Perforce
Circle CI
Go
ThoughtWorks
Integrity
Travis CI
There are many more. We cannot say if Jenkins is better than each because each
has its own unique features. For example, TeamCity offers great .NET support but is
complex and costly, Travis CI is free just like Jenkins and has good documentation
too. Bamboo too offers efficient and faster builds but is not completely free and so
on.
Q40. Name a Jenkins environment variable you have used in a shell script or batch file.
There are numerous environment variables that are available by default in any
Jenkins build job. A few commonly used ones include:
$JOB_NAME
$NODE_NAME
$WORKSPACE
$BUILD_URL
$JOB_URL
Note that, as new Jenkins plug-ins are configured, more environment variables
become available. For example, when the Jenkins Git plug-in is configured, new
Jenkins Git environment variables, such as $GIT_COMMIT and $GIT_URL, become
available to be used in scripts.
All the developers commit their source code changes to the shared Git
repository.
Jenkins server checks the shared Git repository at specified intervals and
detected changes are then taken into the build.
The build results and test results are shared to the respective developers
The built application is displayed on a test server like Selenium and
automated tests are run.
The clean and tested build is deployed to the production server.
The Jenkins “Job DSL / Plugin” is made up of two parts – first, The Domain Specific
Language (DSL) itself that allows users to describe jobs using a Groovy-based
language, and second, a Jenkins plugin which manages the scripts and the updating
of the Jenkins jobs which are created and maintained as a result.
Freestyle project
Maven project
Pipeline
Multibranch pipeline
External Job
Multi-configuration project
Github organization
It is a project that was started with the purpose to rethink the user experience of
Jenkins, modeling and presenting the process of software delivery by surfacing
information that’s important to development teams. This is done with as few clicks
as possible, while still staying true to the extensibility that is core to Jenkins. While
this project is in the alpha stage of development, the intent is that Jenkins users can
install Blue Ocean side-by-side with the Jenkins Classic UI via a plugin
Advanced Questions
Q47. What is Continuous Testing?
Continuous Testing is the process where you execute automated tests as part of
the software delivery pipeline. This is done so that you get the feedback on the
business risks associated with software as early as possible. It consists of evolving
and extending test automation to address the increased complexity and pace of
modern application development and delivery.
Continuous Testing means that testing takes place on a continuous basis without
any disruption of any kind. In a Continuous DevOps process, a software change is
continuously moving from Development to Testing to Deployment. The code
undergoes continuous development, delivery, testing and deployment.
Q48. Explain how you can move or copy Jenkins from one server to another?
I will approach this task by copying the jobs directory from the old server to the
new one. There are multiple ways to do that, I have mentioned it below:
You can:
Move a job from one installation of Jenkins to another by simply copying the
corresponding job directory.
Make a copy of an existing job by making a clone of a job directory by a
different name.
Rename an existing job by renaming a directory. Note that if you change a
job name you will need to change any other job that tries to call the renamed
job.
4. Once you install the plugins , go to Manage Jenkins on your Jenkins dashboard.
You will see your plugins listed among the rest.
Q50. How can you temporarily turn off Jenkins security if the administrative users have
locked themselves out of the admin console?
The JENKINS_HOME folder contains a file named config.xml. When you enable the
security, this file contains an XML element named useSecurity that changes to true.
If you change this setting to false, security will be disabled the next time Jenkins is
restarted.
<useSecurity>false</useSecurity>
However, we must understand that disabling security should always be both a last
resort and a temporary measure. Once you resolve the authentication issues, make
sure that you re-enable Jenkins security and reboot the CI server.
The flowchart below shows the Continuous Delivery Workflow. Hope it will be much
easier to understand with visuals.
Q52. What is the difference between Continuous Delivery and Continuous Deployment?
Continuous deployment means that every change that you make, goes through the
pipeline, and if it passes all the tests, it automatically gets deployed into production.
So, with this approach, the quality of the software release completely depends on
the quality of the test suite as you have automated everything.
Once you have prepared yourself with these Jenkins interview questions, then no
one can stop you from getting your dream job.