Categories

Jang JobsJobsPaperpk

Top 40 Jenkins Interview Questions And Answer

In this article, we will explore Jenkins’ important role in the Software SDLC process with a focus on Jenkins interview questions. Top 40 Jenkins Interview Questions and Answer. Top 40 Jenkins Interview Questions 

Introduction to Continuous Integration & Continuous Deployment and Jenkins’ role as an automation tool in the SDLC process, along with some in-depth discussion on Jenkins’ capabilities & how-to’s specifically focusing on the interview questions about Jenkins at the basic, intermediate, and advanced levels. Top 40 Jenkins Interview Questions

Top 40 Jenkins Interview Questions 

1. What is Jenkins?

Jenkins is a self-contained, open-source automation server that can be used to automate all sorts of tasks related to building, testing, delivering, and deploying software.  

Top 40 Jenkins Interview Questions

2. Can you tell me something about Continuous Integration, Continuous Delivery, and Continuous Deployment?

A software development process wherein changes made to software are integrated into the main code when a patch is ready so that the software is always available for building, testing, deploying, monitoring continuously.

Continuous Delivery is a Software Development Process in which continuously integrated (CI) changes are continuously tested and deployed into a specific environment, typically through manual release procedures after all quality checks have been completed.

Software Development practice whereby continuously integrated (CI) changes are automatically deployed into the target environment after all quality checks are passed.

3. What are the common use cases Jenkins is used for?

Jenkins, being an open-source automation tool, can be used for any kind of software-based automation. Common use-cases include, but are not limited to:

  • Build jobs for software
  • Test jobs for sanity, smoke, CI, and regression
  • Jobs related to web scraping/data scraping
  • Measurement of code coverage
  • Automated general-purpose processes
  • Jobs in reverse engineering
  • There will be many jobs where software automation will be applicable, such as key decoding.

4. What are the ways to install Jenkins?

Jenkins can be installed by using –

  1. Native System Package Manager, such as apt (Linux), brew (Mac).
  2. Docker (popular Docker images for Jenkins are available in the Docker Registry for different platforms like Unix/Mac/Windows).
  3. Our Kubernetes clusters support Kubernetes (available as a Helm chart)
  4. Standalone (any machine with a Java Runtime Environment installed)

Refer to the official documentation for more detailed instructions

5. What is a Jenkins job?

Jobs/Projects are the fundamental unit of logical work (like a software build, an automation task, a test execution, etc) using the Jenkins automation server and the plugins, configurations, and infrastructure required.

It is possible to create different types of jobs, such as a freestyle project, a multi-configuration project, a pipeline project, a multi-branch project, etc.

6. What is a Jenkins Pipeline?

Pipelines are Jenkins jobs that orchestrate long-running activities across multiple build agents – a sequence of steps controlled by logic. It can be used for constructing pipelines (formerly known as workflows) and/or organizing complex activities that cannot be accomplished easily with a freestyle job.

Learn how to create your first pipeline here

7. What are the types of Jenkins pipelines?

Jenkins Pipelines can either be declarative pipelines or scripted pipelines. Declarative pipeline makes use of numerous, generic, predefined build steps/stages (i.e. code snippets) to build our job according to our build/automation needs whereas, with Scripted pipelines, the steps/stages can be custom-defined & used using a groovy syntax which provides better control & fine-tuned execution levels.

8. Explain Jenkins Multibranch Pipeline?

It creates a set of pipeline projects according to the detected branches in one SCM repository. A pipeline can be defined for all branches of a repository, e.g. if we maintain different branches (e.g. production code branches) for different configurations such as locales, currencies, and countries.

9. How do you store credentials in Jenkins securely?

By using the Credentials plugin, Jenkins stores credentials securely, including Username & Password, SSH username & password, Jenkins Build Token, X509 & other certificates, and Vault related credentials securely with encryption & decryption as needed.

10. Is it possible to temporarily stop the execution of a scheduled job?

By disabling the job from the job details page, you will temporarily prevent all scheduled executions & other factors/events from triggering the job, and then re-enabling it, you will resume the scheduled executions and triggers. If a job is no longer required permanently, it can be removed from the jobs list view.

Intermediate Questions

11. What are the ways to trigger a Jenkins Job/Pipeline?

Jenkins offers many ways to trigger a job. The following are some common methods:

  • Send an API (POST) request to the target job URL with the required data.
  • You can trigger it manually from the Jenkins web application.
  • Using Jenkins CLI, trigger it from the master/slave nodes.
  • Triggers based on time, like cron jobs.
  • Events such as SCM actions (Git commits, pull requests), WebHooks, etc.
  • Triggers generated by other Jenkins jobs.

12. What is Jenkins Build Cause?

A Build Cause is a text attribute that indicates what caused the job to be triggered, such as Jenkins User (from UI), Scheduler for Scheduled jobs, Upstream jobs for jobs triggered by upstream jobs, etc. This is mainly used to identify the nature of the build, whether it is nightly, manual, or automated.

13.How does Jenkins know when to execute a Scheduled job/pipeline and how it is triggered?

Jenkins master will set up cron entries based on the scheduled jobs’ configurations. Once the time for a particular job comes, it commands agents (based on the configuration of the job) to execute the job.

14. What are the credential types supported by Jenkins?

Jenkins credentials are used to authenticate with internal/external services so that an action can be completed. Jenkins credentials are managed & provisioned by a plugin called Credentials Binding. Jenkins can handle the following credentials:

  • Token – A token such as an API token, JSON token, etc.
  • Credentials for Basic Authentication can also be stored as username and password.
  • A secret file is used to authenticate secure data services and security handshakes.
  • Machine-to-Machine authentication with an SSH public/private key pair.
  • Certificate – a PKCS#12 certificate file and an optional password.
  • Credentials for the Docker Host Certificate Authentication.

15. What are the Scopes of Jenkins Credentials?

Jenkins credentials can be of one of two scopes – Global or System

Credentials will be applicable to all jobs configured in the Jenkins instance (i.e. for all jobs). User Job (e.g., freestyle, pipeline, or other jobs) authenticating itself with target services/infrastructures for the purpose of the job) would benefit from this.

This is a special scope that allows Jenkins (i.e. the core Jenkins functionality and some installed plugins) to authenticate itself to external services/infrastructures to accomplish certain tasks. Sending emails, etc.

16. What is a Jenkins Shared Library and how it is useful?

The more pipeline jobs an organization uses, the more likely it is that more and more code will be duplicated since a portion of the build/automation processes will be the same for most jobs. As a result, every other upcoming job should also duplicate the same code. Jenkins brings in the concept of shared libraries to eliminate duplication – DRY – Don’t Repeat Yourself.

A shared library is a set of code that is used by more than one pipeline job and is maintained separately. Libraries of this type improve the maintenance, modularity, and readability of pipeline code. Additionally, it speeds up the automation of new jobs.

17.How can Jenkins jobs be triggered, stopped, and controlled programmatically?

Jenkins Remote Access API can be used to do things such as –

  • Obtaining information about jobs, views, nodes, builds, etc. from Jenkins for programmatic consumption.
  • It allows you to trigger a build (both parameterized and non-parameterized), stop/abort a build, enable/disable a job, group/remove jobs from views, etc.
  • Job creation, copying, editing, and deletion.

and many other programming language-specific functionalities. It has wrappers for main programming languages like – Python, Ruby & Java. It can be triggered via CURL as below –

Jobs without parameters

A simple HTTP POST on JENKINS_URL/job/JOBNAME/build.

Parameterized jobs

An example of sending “String Parameters”:

GET JENKINS_URL/job/JOB_NAME/buildWithParameters –user USER:TOKEN –data id=123 –data verbosity=high

18. How can we get the Jenkins version programmatically in Jobs/Pipelines or nodes other than the master?

For Jenkins version checking, open the top-level page or any top-level Remote Access API path, such as ‘…/API/*’, and then check the ‘X-Jenkins’ response header.

Jenkins’ version number is shown here, such as “1.404”. You can also use this to check if an URL is a Jenkins URL.

19.When a Jenkins agent is offline, what is the best practice?

If a job is tied to a specific agent on a specific node, only that agent can run the job and no other agent can fulfill the request. As long as the target node is offline or all the agents on that node are busy building other jobs, the triggered job has to wait until the node is online or an agent from that node is available to execute the triggered build request.

As a result, a triggered job may sometimes wait indefinitely without knowing that the target node is down. Therefore, it is always a good practice to tie the jobs to a group of nodes and agents, referred to as a ‘Label’. When a job is tied to a Label instead of a specific node or agent, any of them can fulfill a build request, when a job is triggered. By doing so, we can reduce the overall turn-around time.

Nevertheless, if a job is waiting for more time for the nodes/agents, it is time to consider adding more nodes/agents.

20. What is the Blue Ocean?

Jenkins’ new user experience is called Blue Ocean. Designed from the ground up for Jenkins Pipeline, but still compatible with freestyle jobs, Blue Ocean reduces clutter and increases clarity. The main features of Blue Ocean are:

  • Visualizations of continuous delivery (CD) Pipelines, allowing for intuitive and fast understanding of your Pipeline’s status.
  • With the Pipeline editor, the creation of Pipelines is simplified by guiding the user through an intuitive and visual process.
  • Individualization according to the role-based needs of each member of the team.
  • Precision when intervention is necessary and/or when issues arise. By identifying where attention is needed in the pipeline, Blue Ocean enables exception handling and increases productivity.
  • Native integration for branches and pull requests, allowing maximum developer productivity when working with others in GitHub, Bitbucket, etc.

21. What is the Jenkins User Content service?

Jenkins has a mechanism called “User Content” that allows administrators to place files in the $JENKINS_HOME/user-content folder, and these files will be served from your host/Jenkins/userContent.

You can think of this as a mini HTTP server to serve images, stylesheets, and other static resources from within Jenkins.

Advanced Interview Questions

22. How is continuous integration achieved using Jenkins?

A developer’s code changes are continuously integrated into the main code, and the same will be tested automatically. The results of the tests then determine whether the change is ready for deployment. During this process –

  • Commit/pull_request made by developer in feature/dev branch
  • The Source Control Management system generates the appropriate events
  • Jenkins Plugins like Git/SVN will detect those events from the configured repositories and trigger build/dependent/test jobs based on these events
  • Upon completion of the Test/Dependent jobs, the change/patch will be labeled according to the status of the test job
  • The Continuous Delivery or Continuous Deployment strategy/tool will take action based on Status (i.e. readiness of a change to be merged with the main branch).

23. What is Artifact Archival & how to do it in Pipelines?

The artifacts of a specific job build are exportable, storable, and archivable. A plugin called – Copy artifact Plugin can be used to set this up. Files and directories matching the configured patterns will be archived for a Jenkins build, which will be useful for future reference. The pipeline can be configured as follows:

Artifacts in archiveArtifacts: ‘output/**/*’

24. How to configure inclusions & exclusions in Artifacts Archival?

Artifact archiving matches target files based on a pattern. Furthermore, it also takes in a pattern (ANT build system pattern for matching files) for exclusion, which will be ignored when selecting the files for archiving.

As an example,

‘output/*.txt’, excludes: ‘output/specific_file.txt’ ArchiveArtifacts artifacts: ‘output/*.txt’

The command above will archive all text files from the output folder except specific_file.txt

25.In a Jenkins job, how can we share information between different build steps or stages?

It is not possible to share information between two different build stages since each runs in its own process. To share info from one build step to another or a post-build action, we can use Files, Database Entries, Environment Variables, etc.

26.How is code coverage measured/tracked using Jenkins in a CI environment?

Using language-specific tools/plugins such as JaCoCo, CodeCov, etc. or generic tools/plugins like Sonarqube that can add the code coverage data to Jenkins builds with some minor tweaks, and the same can be displayed as a graph in Jenkins.

Top 40 Jenkins Interview Questions

27.Default Jenkins Environment Variables & How to introduce custom environment variables?

Jenkins provides several environment variables by default, including BRANCH_NAME, BUILD_NUMBER, BUILD_TAG, and WORKSPACE.

28. How can a job configuration be reset to an earlier version/state?

From the Job details page, we can use the Job Config History to revert changes to the job configurations from the history of changes made to the job. As a result, when a job is misconfigured by mistake, it can easily be reviewed and reverted to an earlier state.

29. How to do Global Tools Configuration in Jenkins?

Global Tools are tools that can be installed outside of the Jenkins environment and controlled from within it. As a result, it requires a Jenkins plugin as well. To use a Global Tool, you generally need to do the following:

  • In order to include the global tool in Jenkins’ list of global tools, install the plugin.
  • Incorporate the tool into Jenkins or provide a way to download and install it during runtime (maybe a command).
  • Click Manage Jenkins -> Global Tools Configuration, scroll through the tool list, and configure the global tool-specific configurations.
  • Use the global tool installed in your job/pipeline.

30. How to create & use a Shared Library in Jenkins?

Jenkins shared libraries can be used in Pipeline Code if the following basic requirements are met:

  • SCM repository for pipeline shared library code.
  • Configure the Jenkins instance with the appropriate SCM plugin.
  • Jenkins Global configuration should include a Global Shared Library.
  • Use the methods defined in the Jenkins Shared Library in the Pipeline Code.

E.g.

#!/user/bin/env groovy

(‘[email protected]’)

31. How do I install a Jenkins plugin that is not available in the Jenkins Update Center?

In general, it is best to use the latest version of a plugin. There are ways, however, to install custom plugins or outdated versions of published plugins. The Jenkins plugins are exported as a .hpi file and can be installed in a variety of ways –

Jenkins CLI: Using Jenkins

http://localhost:8080/install-plugin SOURCE java -jar Jenkins-cli.jar Issuing the [-deploy] command with the [-name VAL] option [-restart]

The above command installs a plugin from a file, a URL, or from the update center.

  • If this points to a local file, it will be installed. Jenkins downloads the URL and installs it as a plugin if it is an URL. Alternatively, the name is assumed to be the short name of the plugin in the existing update center (like “find bugs”), and the plugin will be installed from the update center.
  • -deploy: Deploy plugins immediately without waiting until the reboot.
  • -name VAL: If specified, the plugin will be installed as this short name (whereas normally the name is derived from the source name).
  • -restart Restart Jenkins after successful installation.

Installation via Web UI – advanced

The logged-in Jenkins administrator can upload a .hpi file from within the web UI once the file has been downloaded:

  • Navigate to the Manage Jenkins > Manage Plugins page.
  • Select the Advanced tab.
  • Under the Upload Plugin section, select the .hpi file.
  • The plugin file should be uploaded.
  • Restart Jenkins

Installation via the master – Advanced

In the event a .hpi file has been explicitly downloaded by a system administrator, the administrator can manually place the file in a specific location on the file system.

On the Jenkins controller, copy the .hpi file into the JENKINS_HOME/plugins directory (for example, on Debian systems, JENKINS_HOME is typical/var/lib/Jenkins).

Before the plugin can be loaded and made available in Jenkins, the master needs to be restarted.

32.What is the best way to download the Console log for a Jenkins build programmatically?

Jenkins CLI – console – commands

JRE -jar Jenkins-cli.jar console JOB [BUILD] [-f] [-n N]

The console output of a specific build is produced to stdout as if you were doing “cat build.log”

  • Name of the job:
  • Build number or permalink to the build. It defaults to the last build
  • -f: Append console output as it comes, like tail -f, if the build is in progress
  • Display the last N lines with -n N.

E.g.

SSH -L *ssh_username> -P *port_number> Jenkins_URL> console

33. What is Jenkins Remote Access API?

Jenkins provides an API for most of its functionalities (though some are language-dependent). Currently, it is available in three flavors –

  • HTML
  • JSONP support for JSON
  • Python

APIs for remote access are offered in a REST-like format. As a result, there is no single entry point for all features; instead, they are available under the “…/api/” URL, where the “…” portion represents the data it acts on.

If your Jenkins installation resides at interviewbit.com, visiting /api/ will only display the top-level API features, primarily a list of the configured jobs for this Jenkins instance.

We can access information about a specific build, e.g. https://ci.jenkins.io/job/Infra/job/jenkins.io/job/master/lastSuccessfulBuild/, by going 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.

34. What is In-process Script Approval and how it works?

Jenkins, as well as several plugins, allow users to run Groovy scripts. Jenkins is protected from malicious scripts by running user-provided scripts in a Groovy Sandbox that limits access to internal APIs.

Script Security provides this protection. Any time an unsafe method is used in any of the scripts, the “In-process Script Approval” action should appear in “Manage Jenkins” for the Administrator to decide which unsafe methods, if any, should be allowed.

Jenkins ecosystem security is inherently improved with this in-process script approval.

35. Can we monitor Jenkins using common Observability tools?

Monitoring platforms such as DataDog, Prometheus, JavaMelody & a few others have their corresponding Jenkins plugin, which when configured, sends metrics to the corresponding Monitoring platform, which can then be observed using the latest tools. You can configure Alarms & Notifications for immediate attention when something goes wrong.

36. What is a Ping Thread in Jenkins and how it works?

Jenkins installs a “ping thread” on each remote connection, such as Controller/Agent connections, regardless of how the connection is transported (SSH, JNLP, etc.). Jenkins Remoting Protocol is a message-oriented protocol, and a ping thread periodically sends a message to the receiving end. As the ping thread measures the time it takes for the reply to arrive, if it takes longer than 4 minutes (currently configurable) it assumes that the connection has been lost, and initiates the formal close down.

In order to avoid an infinite hang, some failure modes in the network cannot be detected otherwise. It is also set to a long enough value so that a temporary surge in load or a long garbage collection pause will not break the timeout.

The ping thread is installed on both the controller and agent. Each side pings the other to try to find the problem.

Java.util.logging reports the ping thread time out. Additionally, the controller will also report this exception in the agent launch log. Some agent launchers, most notably SSH agents, write all stdout and stderr outputs from the agent JVM into the same log file, so you need to be careful.

Conclusion

Although these are not all the possibilities of Jenkins, we tried to address some of the commonly asked interview questions. It is also important to realize that the Jenkins Update Center contains thousands of useful plugins that enhance Jenkins’ functionality.

If you are appearing for an interview, you should ensure you have installed Jenkins Server on any of the platforms supported – locally or on the cloud, and that you have installed the most commonly used plugins (suggested by Jenkins and other commonly used plugins). Create a normal freestyle project with Git or another SCM integration plugin and execute some code from the connected Git Repository.

You can also create a pipeline project using JenkinsFile and a global shared Jenkins library and build the job successfully. We will learn how Jenkins actually works with some hands-on issues.

Earn money Online Click Here

Top 40 Jenkins Interview Questions

Top 40 Jenkins Interview Questions
Top 40 Jenkins Interview Questions


Post Views:
3

Leave a Reply

you're currently offline