Chapter 70: DevOps Interview Questions by Topic and Company
70.5 Jenkins Interview Questions
Jenkins ajun pan MNC madhe khup vaparla jato. Pipeline, credentials aani rollback - he teen mudde pakka kara.
What you will learn in this lesson
- 22 real Jenkins questions with short answers
- Which companies asked them, from public interview stories
- Fresher, experienced and senior levels
- A simple way to answer: why, what, how
Why: the problem
Many Indian MNC projects still run Jenkins. They ask how your pipeline works, how secrets are kept, and how you roll back.
What: how to read this lesson
Each question has a short answer in three parts.
- Why: the reason the thing exists.
- What: the plain meaning.
- How: how you use it, often with a small command.
"Asked at" names a company only when a public interview story says the question was asked there. No tag means it is a common question that many companies ask.
Companies with the most questions in this lesson: Infosys (8), Deloitte (5), TCS (4), Tech Mahindra (4), LTIMindtree (2), Accenture (1).
How: answer any question in 4 steps
- Start with the reason. One sentence.
- Give the plain meaning. No big words.
- Show one command or file.
- Add one example from your work. Then stop and wait.
Fresher questions
Q1. How do you set up a CI/CD pipeline in Jenkins?
Why: It is the most asked Jenkins question.
What: A Jenkinsfile in the repo describes stages: checkout, build, test, scan, push image, deploy.
How: Create a Pipeline or Multibranch job pointing to the repo, add credentials, and add a webhook.
pipeline {
agent any
stages {
stage('Build') { steps { sh 'mvn -B package' } }
stage('Test') { steps { sh 'mvn test' } }
}
}
Q2. What is the difference between declarative and scripted pipelines?
Why: You will read both in old projects.
What: Declarative uses a fixed pipeline { } structure and is easier. Scripted is plain Groovy with node { } and more freedom.
How: Prefer declarative; use script { } blocks for small logic.
node { stage('Build') { sh 'make' } }
Q3. How do you trigger a Jenkins job on a GitHub push?
Why: Builds must start without clicking.
What: A GitHub webhook calls Jenkins when code is pushed.
How: Install the GitHub plugin, add the webhook URL (/github-webhook/), enable the trigger in the job. Polling is a fallback.
triggers { githubPush() }
Q4. How do you manage secrets in Jenkins?
Why: Passwords in Jenkinsfiles get leaked.
What: The Credentials store keeps secrets encrypted; withCredentials injects them and masks them in logs.
How: Never echo secrets; prefer a vault (HashiCorp Vault, AWS Secrets Manager).
withCredentials([string(credentialsId: 'sonar-token', variable: 'TOKEN')]) {
sh 'sonar-scanner -Dsonar.token=$TOKEN'
}
Q5. What are Jenkins shared libraries?
Why: Many repos need the same pipeline steps.
What: A shared library is Groovy code in its own repo that pipelines import.
How: Put common steps in vars/, load with @Library.
@Library('ci-lib') _
buildAndPush(image: 'web')
Q6. What is a Jenkins agent (slave)?
Why: Builds should not run on the controller.
What: The controller schedules jobs; agents run them.
How: Use labels to pick agents; use Docker or Kubernetes agents for clean builds.
agent { label 'docker' }
Q7. What are the Maven build lifecycle phases?
Why: Java pipelines run Maven.
What: validate, compile, test, package, verify, install, deploy.
How: Each phase runs all phases before it.
mvn clean package -DskipTests
Q8. Which Maven commands do you use in a pipeline?
Why: Common for Java projects.
What: clean deletes target/, package builds the jar, test runs tests, deploy uploads to a repo.
How: Use -B (batch mode) in CI.
mvn -B clean verify
Q9. Write a Jenkins pipeline to build and push a Docker image.
Why: A common hands-on task.
What: Stages: checkout, build, scan, push.
How: Use credentials for the registry login.
stage('Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'hub', usernameVariable: 'U', passwordVariable: 'P')]) {
sh 'echo $P | docker login -u $U --password-stdin && docker push repo/web:$BUILD_NUMBER'
}
}
}
Q10. What is a multibranch pipeline?
Why: Each branch and PR needs its own build.
What: Jenkins scans the repo and makes one job per branch that has a Jenkinsfile.
How: Good for PR checks.
Q11. What is the post section in a declarative pipeline?
Why: Clean-up and alerts must always run.
What: post runs after stages: always, success, failure, unstable.
How: Send notifications and clean workspace here.
post { failure { echo 'notify team' } always { cleanWs() } }
Experienced questions (2-5 years)
Q12. How do you pass values between Jenkins stages?
Why: Later stages need earlier results.
What: Use environment variables, files, or stash/unstash.
How: Set env.VAR in a script block, or write a file and archive or stash it.
script { env.IMAGE_TAG = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() }
Q13. How do you roll back a failed deployment in Jenkins?
Why: Rollback must be quick and tested.
What: Redeploy the last known good version.
How: Keep versioned artifacts/images; add a rollback stage or job that takes a version parameter; use helm rollback or kubectl rollout undo.
sh "helm rollback web ${params.REVISION}"
Q14. A Jenkins build fails. How do you debug it?
Why: Every DevOps engineer does this weekly.
What: Failure can be code, tests, tools, agent, credentials or network.
How: 1) Read console output from the first error. 2) Re-run on the same agent. 3) Check workspace, tool versions, disk. 4) Reproduce locally. 5) Fix and add a guard.
Q15. How do you back up Jenkins or a pipeline?
Why: Jenkins config is precious.
What: Everything lives in JENKINS_HOME.
How: Keep pipelines as Jenkinsfiles in Git, use Configuration as Code (JCasC), and back up JENKINS_HOME regularly.
tar czf jenkins-backup.tgz -C /var/lib jenkins
Q16. What is a pom.xml dependency and how is it resolved?
Why: Build failures often come from dependencies.
What: pom.xml lists dependencies with groupId, artifactId, version. Maven downloads them from repositories into ~/.m2.
How: Use dependency:tree to find conflicts.
mvn dependency:tree
Q17. How do you set Java heap size for a build or app?
Why: OutOfMemory errors break builds.
What: -Xms sets start heap, -Xmx sets max heap.
How: Set MAVEN_OPTS for builds or JAVA_OPTS for the app; in containers keep it below the memory limit.
export MAVEN_OPTS="-Xmx1g"
Q18. How do you integrate code coverage in CI?
Why: Coverage shows untested code.
What: Tools like JaCoCo create a coverage report during tests.
How: Publish it to SonarQube and fail the gate below a target.
mvn verify jacoco:report
Q19. How do you add a manual approval gate in Jenkins?
Why: Prod changes need a human OK.
What: The input step pauses the pipeline.
How: Add input before the prod stage, limit who can approve, and set a timeout.
stage('Prod') { input message: 'Deploy to prod?', submitter: 'release-team'; steps { sh './deploy.sh prod' } }
Q20. What is the difference between Jenkins and Azure DevOps or GitLab CI?
Why: Interviewers check tool breadth.
What: Jenkins is self-hosted and plugin-based. Azure DevOps and GitLab are platforms with built-in repos, boards and YAML pipelines.
How: Jenkins = most flexible but more upkeep; hosted = less maintenance.
Q21. How do you run Jenkins stages in parallel?
Why: Faster pipelines.
What: The parallel block runs stages at the same time.
How: Run unit tests and lint together.
stage('Checks') { parallel { stage('Lint') { steps { sh 'npm run lint' } } stage('Unit') { steps { sh 'npm test' } } } }
Q22. How do you secure Jenkins?
Why: Jenkins often has keys to prod.
What: Lock down access and plugins.
How: Enable auth and role-based access, no builds on controller, keep plugins updated, use credentials, HTTPS, limit script approvals.
Practice tasks
Easy How do you set up a CI/CD pipeline in Jenkins?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is the difference between declarative and scripted pipelines?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy How do you trigger a Jenkins job on a GitHub push?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy How do you manage secrets in Jenkins?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium How do you pass values between Jenkins stages?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Medium How do you roll back a failed deployment in Jenkins?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What are Jenkins shared libraries?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Easy What is a Jenkins agent (slave)?
Why: Saying it once with your own words makes it stick.
What to do: Answer this question as if the interviewer just asked it.
- Open a lab VM or container, never production.
- Run or write the example from the answer.
- Read the output line by line.
- Say the answer aloud in under 60 seconds.
Check: Your answer has a reason, a plain meaning and one command.
Homework: try at home
- Pick five questions you find hard.
- Write your own answer for each in three lines.
- Record yourself answering them. Listen once and improve.
Recap
In short
- Answer in order: why, what, how, then one example.
- Show one small command when you can.
- "Asked at" comes from public interview stories.
- Practise aloud; do not memorise word for word.
FAQ
Do I need to learn all 22 questions?
No. Start with the fresher ones. Then add the experienced ones for your level.
Should I memorise these answers?
No. Understand the why, then say it in your own words. Interviewers notice memorised lines.
What if I do not know an answer?
Say so honestly. Then explain how you would find out, step by step.
Are these questions only for one company?
No. "Asked at" shows where people said it was asked. Other companies ask the same things.
How long should an answer be?
About 30 to 60 seconds. Give a reason, a plain meaning and one example.
Is a lab really needed?
Yes. Running the command once makes your answer real and confident.
Interview questions
Practise these five first. Many companies asked them.
- How do you trigger a Jenkins job on a GitHub push? - A GitHub webhook calls Jenkins when code is pushed.
- How do you manage secrets in Jenkins? - The Credentials store keeps secrets encrypted; withCredentials injects them and masks them in logs.
- A Jenkins build fails. How do you debug it? - Failure can be code, tests, tools, agent, credentials or network.
- How do you set up a CI/CD pipeline in Jenkins? - A Jenkinsfile in the repo describes stages: checkout, build, test, scan, push image, deploy.
- What are the Maven build lifecycle phases? - validate, compile, test, package, verify, install, deploy.
Quick quiz
Q1. How do you set up a CI/CD pipeline in Jenkins?
A Jenkinsfile in the repo describes stages: checkout, build, test, scan, push image, deploy.
Q2. What is a Jenkins agent (slave)?
The controller schedules jobs; agents run them.
Q3. What is the difference between Jenkins and Azure DevOps or GitLab CI?
Jenkins is self-hosted and plugin-based.
Samajla ka?
Revision card
Interview card