Jenkins
Jenkins
com/tag/jenkins/:
https://naveenautomationlabs.com/tag/git/
Jenkins is an Open Source Continuous integration tool that is written in Java which is often used in
Devops.
It is mainly used by Developers and Testers, whenever Developers/Testers does any changes in
Source Code then Jenkins will automatically pull the code and continuously build and test code that
has been added.
Go to any browser and search by Jenkins Download as shown below and click on below
highlighted link.
After clicking on above highlighted link, you will be navigated to below page.
Click on “Permalink to the latest” – Latest and Stable version of Jenkins War File will be installed
into your local system.
Now you are good to execute your Jenkins War File from Command Prompt.
Step 2: Executing Jenkins War File from Command Prompt.
Create a separate folder in your local system and place Jenkins War file once it is
downloaded. Note: We must run Jenkins.war file through Command Line Prompt.
Note: By default, Jenkins will always run in localhost:8080. Make sure nothing else is running on
port 8080. If localhost:8080 is already occupied then you won’t be able to execute Jenkins.war file.
In such case you can execute your Jenkins.war file in other port using below command.
Once Jenkins is successfully launched, user should be able to see below message in
Command Prompt.
Step 4: Now, go to browser and open localhost:8084 where you have run your Jenkins.
In my case, I have run Jenkins in port 8084.
When launching it for first time, you have to set username and password and install default plug-ins
that suggests etc and then you will be landed on to Jenkins Dashboard Page.
Step 5: Configure your system for Java and Maven in Jenkins as shown below
Step 6: Install Required Plug-ins >> Go to Manage Jenkins >> Manage Plug-ins and install from
Available Section.
Step 7: Create Job >> New Item >> Enter Item Name >> Select Maven Project and Click on OK.
After installing all Maven Plug-ins user should be able to see Maven Project Option.
C. Go to Source Code Management. [You have to select any one option from it].
Select None, if you are not using any Source Code Management tool for maintaining Code.
Select Git and provide Repository URL and Branch Name, if you are maintaining code in Git.
D. Go to Build Triggers.
You can select as shown below, if you are not scheduling jobs using CRON Command and such. [In
this case you have to build a job manually].
If you have to schedule jobs automatically, select Build Periodically and use CRON Command.
By setting the schedule period to 15 13 * * * you tell Jenkins to schedule the build
every day of every month of every year at the 15th minute of the 13th hour of
the day.
Jenkins used a cron expression, and the different fields are:
1. MINUTES Minutes in one hour (0-59)
2. HOURS Hours in one day (0-23)
3. DAYMONTH Day in a month (1-31)
4. MONTH Month in a year (1-12)
5. DAYWEEK Day of the week (0-7) where 0 and 7 are sunday
If you want to schedule your build every 5 minutes, this will do the job : */5 * * * *
If you want to schedule your build every day at 8h00, this will do the job : 0 8 * *
*
If we have to build a job automatically when in any commit happens to Git then we
can select Poll SCM and use CRON Command.
G. From Build, Enter Path for your Root POM.xml and command to be executed as shown below.
Note: When in giving Maven Command to Run Test Cases in Jenkins, ignore mvn and just give commands as below.
clean install Or test Or test -PSmoke etc.
H. From Post Steps, you can select any option as per your requirement.
I. If you want to be notified, when in any job is getting failed then you can select Build Settings and
configure it.
Note: To do this we need to do other extra configuration [You can ignore for it now].
J. Post Build Actions can be used to Generate Results. [To achieve it, we need to install required
plug-ins like TestNG Plug-in, HTML Report Plug-in for Generating Extent Report]
Below Configurations needs to be done for generating Extent Reports in Project Folder.
Step 9: Apply and Save, now click on Build now to trigger your Job.
Conclusion: In this blog, we have seen how to create a Job for Maven Project,
Configuring Job and Executing a Job in Jenkins.
https://www.softwaretestinghelp.com/jenkins-interview-questions/
We are sure that this will be useful for freshers and experienced professionals who want to
start their career with Jenkins.
All the topics right from the basics till advanced concepts of SQL have been covered here
for your reference. It will definitely be helpful for the readers to have a quick revision of
some important concepts before appearing for an interview.
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.
Q #13) What are Declarative Pipelines in Jenkins?
Answer: Declarative Pipelines are the newest additions to Jenkins that simplify the groovy
syntax of Jenkins pipelines (top-level pipeline) with some exceptions, such as:
No semicolon to be used as a statement separator. The top-level pipeline should be
enclosed within block viz;
/* Declarative Pipeline */
pipeline {
agent any
stages {
stage(‘Build’) {
steps {
// Statements…
}
stage (‘Test’) {
steps {
// Statements…
scm:
git:
url: ssh://Jenkins.org/eloc.git
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 p
and describes the software with Continuous Integration and facilit
dependencies. Continuous Deliver.
Supports projects written in C#, Supports projects written in C Supports version control tools like Git,
Ruby. and C++. AccuRev.
Executes Unit Tests as a part of the Supports single file execution Can execute Apache Ant and Apache M
normal build cycle. introduced with Java II.
Q #22) How will you define Post in Jenkins?
Answer: Post is a section that contains several additional steps that might execute after
the completion of the pipeline. The execution of all the steps within the condition block
depends upon the completion status of the pipeline.
The condition block includes the following conditions – changed success, always, failure,
unstable and aborted.
Q #23) What are Parameters in Jenkins?
Answer: Parameters are supported by the Agent section and are used to support various
use-cases pipelines. Parameters are defined at the top-level of the pipeline or inside an
individual stage directive.
Q #24) How you can set up a Jenkins job?
Answer: Setting up a new job in Jenkins is elaborated below with snapshots:
Step 1: Go to the Jenkins Dashboard and log in with your registered login credentials.
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.
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.
Q #26) How can You Clone a Git Repository via Jenkins?
Answer: To create a clone repository via Jenkins you need to use your login credentials in
the Jenkins System.
To achieve the same you need to enter the Jenkins job directory and execute the git
config command.
Q #27) How can you secure Jenkins?
Answer: Securing Jenkins is a little lengthy process, and there are two aspects of
securing Jenkins:
(i) Access Control which includes authenticating users and giving them an appropriate set
of permissions, which can be done in 2 ways.
Security Realm determines a user or a group of users with their passwords.
Authorization Strategy defines what should be accessible to which user. In this
case, there might be different types of security based on the permissions granted to
the user such as Quick and simple security with easy setup, Standard security setup,
Apache front-end security, etc.
(ii) Protecting Jenkins users from outside threats.
Q #28) How to create a backup and copy files in Jenkins?
Answer: In Jenkins, all the settings, build logs and configurations are stored in the
JENKINS_HOME directory. Whenever you want to create a backup of your Jenkins you can
back up JENKINS_HOME directory frequently.
It consists of all the job configurations and slave node configurations. Hence, regularly
copying this directory allows us to keep a backup of Jenkins.
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 2: Click on Manage Plugins that appears on the next page.
Step 3: Go to Available Tab on the next page and search for ThinBackup.
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 #30) What is Flow Control in Jenkins?
Answer: In Jenkins, flow control follows the pipeline structure (scripted pipeline) that are
being executed from the top to bottom of the Jenkins file.
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).
Q #32) What are the basic requirements for installing Jenkins?
Answer: For installing Jenkins you need the following system configuration:
1. Java 7 or above.
2. Servlet 3.1
3. RAM ranging from 200 MB to 70+ GB depending on the project build needs.
4. 2 MB or more of memory.
Q #33) How can you define a Continuous Delivery Workflow?
Answer: The flowchart below shows the Continuous Delivery Workflow. Hope it will be
much easier to understand with visuals.
Q #34) What are the various ways in which the build can be scheduled in Jenkins?
Answer: The build can be triggered in the following ways:
1. After the completion of other builds.
2. By source code management (modifications) commit.
3. At a specific time.
4. By requesting manual builds.
Q #35) Why is Jenkins called a Continuous Delivery Tool?
Answer: We have seen the Continuous Delivery workflow in the previous question, now
let's see the step by step process of why Jenkins is being called as a Continuous Delivery
Tool:
1. Developers work on their local environment for making changes in the source code
and push it into the code repository.
2. When a change is detected, Jenkins performs several tests and code standards to
check whether the changes are good to deploy or not.
3. Upon a successful build, it is being viewed by the developers.
4. Then the change is deployed manually on a staging environment where the client
can have a look at it.
5. When all the changes get approved by the developers, testers, and clients, the final
outcome is saved manually on the production server to be used by the end-users of
the product.
In this way, Jenkins follows a Continuous Delivery approach and is called
the Continuous Delivery Tool.
Q #36) Give any simple example of Jenkins script.
Answer: This is a Jenkins declarative pipeline code for Java:
pipeline {
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.
Conclusion
The above-mentioned interview questions are being asked during Jenkins Software
Configuration Management and DevOps interview as Jenkins is also considered as an
important tool in the DevOps program.
The real-time Jenkins interview questions listed in this article can be referred by beginners,
professionals as well as job seekers who are looking for a good opportunity or a technical
position in Jenkins.
EDUREKA:
Careers
DevOps
Topics Covered
DevOps (73 Blogs)
Mastering Git and GitHub (9 Blogs)
Docker (8 Blogs)
DevOps Engineer Masters Program (4 Blogs)
SEE MORE
9 Comments
Bookmark
3 / 9 Blog from DevOps Interview Questions
Jenkins Interview Questions
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.
Instructor-led Sessions
Real-life Case Studies
Assignments
Lifetime Access
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
Soon after a commit occurs, the Jenkins server detects the changes
that have occurred in the source code repository. Jenkins will pull those
changes and will start preparing a new build.
If the build is successful, then Jenkins deploys the build in the test
server.
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.
4. Deploy Jenkins war File – You deploy Jenkins war file using Tomcat
to run 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.
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:
AccuRev
CVS
Subversion
Git
Mercurial
Perforce
Clearcase
RTC
Post is a section that contains several additional steps that might execute
after the completion of the pipeline. The execution of all the steps within the
condition block depends upon the completion status of the pipeline. The
condition block includes the following conditions – changed success,
always, failure, unstable and aborted.
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
Q16. How Can You Clone A Git Repository Via Jenkins?
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.
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.
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.
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.
Command-line – to start the node agent using the command line, the
client needs the executable agent.jar file. When this file is run, it
simply launches a process on the client to communicate with the
Jenkins master to run build jobs.
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.
Q35. How can you use a third-party tool in Jenkins?
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.
Q38. What is DevOps and in which stage does Jenkins fit in?
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.
$JOB_NAME
$NODE_NAME
$WORKSPACE
$BUILD_URL
$JOB_URL
The build results and test results are shared to the respective
developers
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?
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:
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>
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.