Google News
logo
Java Jenkins Interview Questions
Jenkins is a self-contained, open-source automation server that can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed.
To install Jenkins, you just need to follow these five steps :
 
Install Java Version 8 : Jenkins is a Java based application, hence Java is a must.
 
Install Apache Tomcat Version 9 : Tomcat is essential to deploy Jenkins war file.
 
Download Jenkins war File : This war is must to install Jenkins.
 
Deploy Jenkins war File : You deploy Jenkins war file using Tomcat to run Jenkins.
 
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.
Some of the crucial features of Jenkins are the following :
 
* It is a free and open-source automation tool
* Jenkins provides a vast number of plugins
* It is easy to set up and install on multiple operating systems
* Provides pipeline support
* Fast release cycles 
* Easy upgrades
In software development, multiple developers or teams work on different segments of same web application so you have to perform integration test by integrating all modules. In order to do that an automated process for each piece of code is performed on daily bases so that all your codes get tested. This process is known as continuous integration.
Jenkins being open-source automation can be used for any kind of software-based automation. Some of the common use-cases include but not limited to :
 
* Software build jobs
* Sanity/Smoke/CI/Regression test jobs
* Web/Data Scraping related jobs
* Code coverage measurement jobs
* General-purpose automation
* Reverse Engineering jobs
* Key Decoding jobs & many other jobs where software automation will be applicable.
Jenkins supports the following SCM tools :
 
* AccuRev
* CVS
* Subversion
* Git
* Mercurial
* Perforce
* Clearcase
* RTC
A Job/Project is the fundamental unit of a logical work (like a software build, an automation task, test execution, etc) using the Jenkins automation server and other required plugins, configurations & infrastructures.
 
Jobs can be of different types like : a freestyle project, a multi-configuration project, a pipeline project, a multi-branch project, etc.
Advantage of Jenkins includes :
 
* Bugs tracking are easy at early stage in development environment.
* Provides a large numbers of plugin support.
* Iterative improvement to the code.
* Build failures are cached at integration stage.
* For each code commit changes an automatic build report notification generates.
* To notify developers about build report success or failure, it is integrated with LDAP mail server.
* Achieves continuous integration agile development and test driven development.
* With simple steps, maven release project is automated.
* Apache Groovy is a dynamic object-oriented programming language used as a scripting language for Java platforms. 

* Groovy is used to orchestrate the Jenkins pipeline and enables different teams to contribute in different languages. 

* Groovy's syntax is very similar to that of Java, making it more seamless with the Java interface. 

* The language with several features like Java compatibility and Development support.
Commands that can be used to start Jenkins are :
 
* Open the command prompt

* After the command prompt opens, browse to the directory where Jenkins war is present

* Then run the following command :

D:\>Java -jar Jenkins.war
Continuous Integration : A software development process where the changes made to software are integrated into the main code as and when a patch is ready so that the software will be always ready to be - built, tested, deployed, monitored - continuously.
 
Continuous Delivery : This is a Software Development Process where the continuously integrated (CI) changes will be tested & deployed continuously into a specific environment, generally through a manual release process, after all the quality checks are successful.
 
Continuous Deployment : A Software Development practice where the continuously integrated (CI) changes are deployed automatically into the target environment after all the quality checks are successful.
CI/CD Pipeline or Continuous Integration/ Continuous Delivery is referred to as the DevOps approach's backbone. The pipeline is responsible for building codes, running tests, and deploying new software versions.
* The pipeline represents the continuous delivery and continuous integration of all the jobs in the SDLC and DevOps life-cycle. 

* It connects this pipeline in a particular format by Jenkins. Jenkins pipeline is a set of plugins that support implementation and Integration of continuous delivery pipelines into Jenkins. 

* The Jenkins pipeline solves several problems like the maintenance of thousands of jobs and maintaining deployment with no other powerful methods.
Credentials can be stored securely in Jenkins using the Credentials plugin, which stores different types of credentials like - Username with a password, SSH username with the private key, AWS Credentials, Jenkins Build Token, Secret File/Text, X509 & other certificates, Vault related credentials securely with proper encryption & decryption as and when required.
There are many ways we can trigger a job in Jenkins. Some of the common ways are as below -
 
* Trigger an API (POST) request to the target job URL with the required data.
* Trigger it manually from the Jenkins web application.
* Trigger it using Jenkins CLI from the master/slave nodes.
* Time-based Scheduled Triggers like a cron job.
* Event-based Triggers like SCM Actions (Git Commit, Pull Requests), WebHooks, etc.
* Upstream/Downstream triggers by other Jenkins jobs.
It is a pipeline job that can be configured to Create a set of Pipeline projects according to the detected branches in one SCM repository. This can be used to configure pipelines for all branches of a single repository e.g. if we maintain different branches (i.e. production code branches) for different configurations like locales, currencies, countries, etc.
Follow these steps to move or copy Jenkins from one server to another :
 
* First, copy the related job directory and slide a job from one installation of Jenkins to another.
* Make a copy of an already existing job by making clone of a job directory by a different name.
* Renaming an existing job by rename a directory.
You can use any one of the following commands to start Jenkins manually :
 
* (Jenkins_url)/restart : Forces a restart without waiting for builds to complete.
* (Jenkin_url)/safeRestart : Allows all running builds to complete.
Some most useful plugins in Jenkins :
 
* Maven 2 project
* Amazon EC2
* HTML publisher
* Copy artifact
* Join
* Green Balls
If you want to create a back-up of your Jenkins setup, just copy the directory that saves all the setting, build artifacts and logs of Jenkins in its home directory. You can also copy a job directory to clone or replicate a job or rename the directory.
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.
Jenkins credentials can be of one of the two scopes : Global & System
 
Global : the credential will be usable across all the jobs configured in the Jenkins instance (i.e. for all jobs). This is more suited for user Jobs (i.e. for the freestyle, pipeline, or other jobs) to authenticate itself with target services/infrastructures to accomplish the purpose of the job)
 
System : This is a special scope that will allow the Jenkins itself (i.e. the core Jenkins functionalities & some installed plugins) to authenticate itself to external services/infrastructures to perform some defined tasks. E.g. sending emails, etc.
As an organization starts using more and more pipeline jobs, there is a chance for more and more code being duplicated in every pipeline job, since a part of the build/automation processes will be the same for most of the jobs. In such a situation, every other new upcoming job should also duplicate the same piece of code. To avoid duplications, the Jenkins project brought in the concept of Shared Libraries, to code - DRY - Don't Repeat Yourself.
 
Shared libraries are a set of code that can be common for more than one pipeline job and can be maintained separately. Such libraries improve the maintenance, modularity & readability of the pipeline code. And it also speeds up the automation for new jobs.
Jenkins file is a text file that has a definition of a Jenkins pipeline and is checked into the source control repository. It enables code review and iteration on the pipeline. It also permits an audit trail for the pipeline.
The answer to this is pretty straightforward. To use Jenkins you require :
 
* A source code repository which is accessible, for instance, a Git repository.
* A working build script, e.g., a Maven script, checked into the repository.
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.
According to me, the integration of Jenkins is possible with the following :
 
* Version Control system like GIT, SVN.
* Build tools like Apache Maven.

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.
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.
Below are the steps to deploy a custom build of a core plugin :
 
* 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.
Agent : It is directive to tell Jenkins to execute the pipeline in a particular manner and order.
 
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.
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.
There are 2 ways to start the node agent :
 
Browser : if Jenkins node agent is launched from a browser, a JNLP (Java Web Start) file is downloaded. This file launches a new process on the client machine to run jobs.
 
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.
DevOps is a software development practice that blends software development (Dev) with the IT operations (Ops) making the whole development lifecycle simpler and shorter by constantly delivering builds, fixes, updates, and features. Jenkins plays a crucial role because it helps in this integration by automating the build, test and deployment process.
The Jenkins “Job DSL / Plugin” is made up of two partsfirst, 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.
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.
The SCM or Source Code Management tools Jenkins supports are SVN, Clearcase, CVS, Git, AccuRev, Perforce, RTC, Mercurial.
Blue ocean is a modern UI for Jenkins, which helps in a personalized experience with modern design. Through this interface, any user can create, diagnose and visualize Continuous Delivery pipelines. It doesn’t need technical skills to create or understand the pipelines as everything is visually presented. Also, detection of automation problems is easy as each step can be easily navigated.
The agent directive directs Jenkins on how and where to execute the Pipeline or its subsets. All the pipelines require agents. The agent causes a workspace to be allocated that contains checkout files from source control and other additional working files required for the Pipeline. It also causes the steps required for execution to be executed by Jenkins when an executor is available.
Jenkins is a CI tool, whereas Ant and Maven are build tools. Jenkins provides a trigger for the build to be executed. Maven and Ant can only perform build operations; however, Jenkins can run unit tests, deploy applications automatically.
 
Between Ant and Maven, Ant is just a tool and is procedural, whereas Maven is a complete declarative framework and has a lifecycle. Ant scripts cannot be reused, but Maven plugins can be reused. Ant is an old tool used by legacy systems. Most new applications use Maven.
Using the Jenkins CLI - console - command
 
java -jar jenkins-cli.jar console JOB [BUILD] [-f] [-n N]
 
Produces the console output of a specific build to stdout, as if you are doing 'cat build.log'
 
* JOB : Name of the job
* BUILD : Build number or permalink to point to the build. Defaults to the last build
* -f : If the build is in progress, append console output as it comes, like tail -f
* -n N : Display the last N lines.

Ex :
 
ssh -l <ssh_username> -p <port_no> <Jenkins_URL> console <JOB_NAME>

Jenkins provides remote access API to most of its functionalities (though some functionalities are programming language-dependent). Currently, it comes in three flavors :
 
* XML
* JSON with JSONP support
* Python

Remote access API is offered in a REST-like style. That is, there is no single entry point for all features, and instead, they are available under the ".../api/" URL where the "..." portion is the data that it acts on.
 
For example, if your Jenkins installation sits at interviewbit.com, visiting /api/ will show just the top-level API features available – primarily a listing of the configured jobs for this Jenkins instance.
 
Or if we want to access information about a particular build, e.g. https://ci.jenkins.io/job/Infra/job/jenkins.io/job/master/lastSuccessfulBuild/, then go to https://ci.jenkins.io/job/Infra/job/jenkins.io/job/master/lastSuccessfulBuild/api/ and you’ll see the list of functionalities for that build.
Common monitoring platforms like DataDog, Prometheus, JavaMelody & few others - have their corresponding Jenkins plugin, which when configured, sends Metrics to the corresponding Monitoring platform, which can then be Observed with the latest tools & technologies. The same can be configured with Alarms & Notifications for immediate attention when something goes wrong.
Some of the Jenkins Pipeline key aspects are :
 
Pipeline : User-defined model of a CD pipeline. Pipeline's code takes the role of defining the entire build process, including building, testing, and delivering an application.

Node : A machine as a part of the Jenkins environment which is capable of executing a pipeline.

Step : An individual task that communicates to Jenkins about what to do at a particular point in time.

Stage : This defines distinct subset of tasks that are conceptually unique and performed through the pipeline (build, test, deploy stages).
* JENKINS_HOME directory is the place where all the settings, logs, and configurations are stored. It stores all this information in XML files. 

* The directory contains a subdirectory for every Jenkins build job being operated. 

* Every directory has two subdirectories:  builds and workspace., and some other files as well.

* These sub directories are important, as the workspace directory is located at the place where Jenkins is building the project, and it contains the source code.

* The builds directory stores the history of all the builds performed for this job. 
The three mechanisms are as follows :
 
* Jenkins uses an internal database to store user data and credentials.
* Jenkins can use a lightweight Directory Access Protocol (LDAP) server to authenticate users.
* We can configure Jenkins to employ the application server's authentication mechanism upon which we deploy it.