Jenkins Interview Questions- Part 4

Jenkins Interview Questions- Part 4For those who already have some hands-on experience with Jenkins, interviews may include deeper questions about Jenkinsfiles, pipeline stages, plugin management, and integrations with other DevOps tools. Jenkins is a key part of many companies’ CI/CD pipelines, and being able to explain how you’ve used it in real projects is important.
This page shares a collection of intermediate to advanced Jenkins interview questions along with clear and helpful answers. It’s ideal for candidates applying for roles like DevOps Engineer, Automation Tester, or Site Reliability Engineer. You’ll find questions on declarative vs. scripted pipelines, security setup, plugin use, and integration with version control systems like Git.

Answer:

  • Agent: It is a directive to guide Jenkins on executing the Pipeline in a particular order & manner.
  • Post-section: If you add some notification to perform other tasks at the end of the Pipeline, the post-section will run at the end of each Pipeline’s execution.
  • Jenkinsfile: It is a text file wherein all the definitions of Pipelines are defined. It is checked in the source control repository.

Answer:

We need the following to use Jenkins:

  1. An accessible source code repository like a Git repository
  2. A working build script, such as a Maven Script, checked into the repository

Answer:

The following are the types of jobs in Jenkins:

  • Pipeline
  • External Job
  • Maven project
  • Freestyle project
  • Multibranch Pipeline
  • Multi-configuration project
  • GitHub organization

Answer:

A Scripted Pipeline is built on the top of an underlying Pipeline sub-system. Unlike Declarative, Scripted Pipeline is an efficient general-purpose DSL built with Groovy. Most functionality provided by the Groovy language is made accessible to Scripted Pipeline users, meaning it is a flexible tool with which one can author continuous delivery pipelines.

Answer:

Environment Directive represents a sequence of key-value pairs defined as Environment Variables for all steps, based on where the Environment Directive is located in the Pipeline. It supports a special helper method credentials() used to access predefined credentials by their identifier in the Jenkins environment.

Answer:

Below are the ways of scheduling build in Jenkins:

  • By source code management commits.
  • After the completion of other builds.
  • Build could be scheduled to run at a particular time using the CRON jobs.
  • The build could be scheduled through Manual Build Requests.

Answer:

The role-based strategy plugin provides three main functionalities:

  • Global roles: Across a project with permission job, run & Source Control Management (SCM)
  • Project role: It can access a particular project job or run a category
  • Slave roles: It only sets the node-related permissions.

Answer:

A stage block denotes conceptually distinct subparts of tasks performed in the entire Pipeline. Stages have a sequence of multiple-stage directives; the stages section contains a bulk of “work” described by the Pipeline. It is recommended that stages have at least one stage directive for each distinctive part of the continuous delivery process, like Test, Build, & Deploy.

Answer:

Flow control in Jenkins supports the scripted pipeline or pipeline structure for executing the top to bottom of a Jenkins file.

Answer:

The declarative pipeline is a relatively new Jenkins feature that supports a pipeline as a code concept. It simplifies pipeline code & makes it easier to read & write. The pipeline code is written in the Jenkinsfile, which can be checked into the source control management system like Git. The structure & syntax of a declarative pipeline is as follows:

  • any- It denotes the entire pipeline will run on any available agent.
  • docker- It helps to run a pipeline in a Docker environment.
  • none- It represents that all the stages under a block will have to be declared with an agent separately.
  • label- It is only a label for the Jenkins environment.

Answer:

An SCM or Source Code Management specifies the location of a source code in Jenkins. The entry point to an SCM is defined as jenkins_jobs.scm. A job defined with the SCM attribute accepts numerous SCM definitions. Some of the popular SCM tools are Git, CVS, Clearcase, Perforce, AccuRev, Subversion, Mercurial, & RTC.

Answer:

  1. Jenkins, by default, runs on a port number 8080; if you want to change the existing port from 8080 to any other desired port number, take the following steps:
    • Run Jenkins with the command line;
    • Then, execute the command, java -jar -httpPort=desired_port jenkins.war.
  2. If Jenkins is installed with the Windows package, then:
    • Go to the Jenkins directory or Program Files;
    • And, open Jenkins.xml in the editor
    • Find –httpPort=8080 & replace the port number 8080 with a new port number.

Answer:

To configure Docker in Jenkins, follow these steps:

  • First, click on the “Manage Jenkins” on the Jenkins dashboard;
  • Select the “Manage Plugins” on the Configuration page;
  • Now, click on Available in the tabbed interface & it will list all the available Jenkins plugins for installation;
  • Search for the Docker plugin in the search box; you get to choose from multiple Docker plugins;
  • Finally, select the Docker plugin.

Answer:

You can use the GitHub plugin whenever you want to integrate Jenkins with GitHub projects. It enables scheduling a build, pulling code files & data from the GitHub repos to a Jenkins machine, and automatically triggers each build on the Jenkins server after each commit on the Git repository. It saves time & allows you to incorporate a specific project into the CI process.

Answer:

Follow these steps to configure Jenkins with Maven:

  1. Go to the Jenkins dashboard & navigate to Manage Jenkins, select Configure System;
  2. Now scroll down till you see the Maven section & go to Add Maven;
  3. Uncheck the ‘Install automatically’ box;
  4. Add & save a name for the setting & location of the MAVEN_HOME;
  5. Now, you can create a job with a ‘Maven project’ option.

Answer:

You can create the slave node in Jenkins by these simple steps:

  1. Click on the Manage Jenkins option
  2. Select the option Manage Nodes
  3. Enter a name for the slave node & click OK
  4. Save the changes