13 Jenkins - gannurohith/devops-interview-wiki GitHub Wiki
DevOps / QA Interview Q&A Bank – GitHub Markdown Version
(...Previous content remains unchanged...)
📁 13 - Jenkins (Scenario-Based Q&A for 5+ Years Experience)
-
Scenario: You are asked to install Jenkins and run it on a custom port 8081. How do you achieve this?
- Edit
/etc/default/jenkins
or the systemd service file and changeHTTP_PORT=8081
. - Restart Jenkins:
sudo systemctl restart jenkins
- Edit
-
Scenario: How do you secure a freshly installed Jenkins server?
- Enable global security and disable CLI over remoting
- Install Role-Based Strategy Plugin
- Configure CSRF protection and HTTPS
-
Scenario: Create users
Devops
andTesting
with limited access in Jenkins. How do you do it?- Use Role-Based Strategy Plugin
- Define roles and assign them to specific users under “Manage and Assign Roles”
-
Scenario: How do you configure Jenkins nodes (slaves) and restrict jobs using labels?
- Assign labels under node configuration
- In the job config, use “Restrict where this project can be run” and specify the label
-
Scenario: You have to create Jenkins jobs for this GitHub repo:
https://github.com/betawins/Techie_horizon_Login_app.git
. What steps do you follow?- Create a Freestyle or Pipeline job
- Connect GitHub and enter repo URL
- Add build steps like Maven or shell commands
-
Scenario: How do you configure a Jenkins job using a private GitHub repository?
- Generate a personal access token or SSH key
- Store credentials in Jenkins using “Credentials” plugin
- Use those credentials in job configuration
-
Scenario: You are asked to configure two slave machines for Jenkins. What are the methods?
- Use SSH or JNLP agent
- Install Java on slave and connect with Jenkins master using credentials or agent.jar
-
Scenario: How do you set up a webhook to trigger a Jenkins job from GitHub?
- Enable GitHub plugin in Jenkins
- Set GitHub webhook URL to:
http://<jenkins-url>/github-webhook/
- Enable “GitHub hook trigger for GITScm polling” in job
-
Scenario: You want to use Poll SCM to trigger builds. What cron syntax do you use?
- Use “Poll SCM” and define cron like:
H/5 * * * *
for every 5 minutes
- Use “Poll SCM” and define cron like:
-
Scenario: How do you configure Jenkins job for scheduled builds?
- Use “Build periodically” option and define cron syntax (e.g.,
@daily
,H 0 * * *
)
- Scenario: You need to automate Jenkins backup using a shell script. What files do you back up?
- Backup
/var/lib/jenkins/
, especiallyjobs/
,plugins/
,secrets/
, andconfig.xml
- Scenario: Create a Bash script to back up Jenkins. How do you schedule it?
- Use
tar -czf jenkins_backup.tar.gz /var/lib/jenkins
- Schedule via crontab:
0 2 * * * /path/to/script.sh
- Scenario: What is the purpose of the ThinBackup or RethinBackup plugin?
- Automates job and config backups with scheduling, retention, and restore options
- Scenario: You want to restore a Jenkins server from a backup. What are the steps?
- Stop Jenkins, replace contents of
/var/lib/jenkins/
with backup, start Jenkins - Ensure correct permissions and restart Jenkins service
- Scenario: What Jenkins plugin allows you to manage fine-grained access control for different users?
- Role-Based Strategy Plugin
- Scenario: How do you configure job chaining in Jenkins (trigger one job after another)?
- Use “Build other projects” or use Pipeline syntax with
build job: 'job_name'
- Scenario: What is a safe way to update Jenkins plugins and core?
- Use “Manage Jenkins → Plugins”, check compatibility
- Always take backup before update
- Scenario: A Jenkins job is stuck at workspace cleanup. What could be the reason?
- File permission issues or large workspace size
- Use
ws-cleanup
plugin or manual cleanup script
- Scenario: Jenkins is running out of disk space. What actions do you take?
- Clean up old builds and workspaces
- Configure build retention policies
- Archive logs and backups externally
- Scenario: You want to notify developers on job status. How do you implement this?
- Use Email-ext plugin or integrate with Slack/MS Teams
- Scenario: Jenkins is throwing 'Permission denied' when accessing Git repo. What are the causes?
- Incorrect SSH permissions or missing credentials in Jenkins
- Scenario: How do you secure credentials in Jenkins Pipeline?
- Use
withCredentials()
block with credentials stored in Jenkins credentials manager
- Scenario: How do you handle secrets securely in Jenkins pipelines?
- Use Jenkins credentials binding plugin and avoid echoing secrets in console
- Scenario: Jenkins job is not triggering via webhook. How do you troubleshoot?
- Check webhook delivery logs in GitHub
- Check Jenkins logs and job trigger config
- Scenario: Jenkins pipeline is failing due to environment mismatch. How do you ensure consistency?
- Use Docker agents or configure consistent slave environments
- Scenario: What are best practices to ensure Jenkins stability in production?
- Limit number of concurrent jobs
- Use dedicated nodes for builds
- Regularly back up and monitor resource usage
- Scenario: How do you configure Jenkins for CI/CD in a microservice-based repo?
- Use multibranch pipelines
- Dynamically detect services using Jenkinsfiles in subdirectories
- Scenario: Jenkins restart loses config. How do you prevent it?
- Ensure persistent volume for
/var/lib/jenkins
in Docker or VM setup
- Scenario: Restore Jenkins to a specific point after job misconfiguration.
- Use backup snapshot or GitOps-managed Jenkins configuration
- Scenario: You want to version control Jenkins pipeline code. What’s the approach?
- Store
Jenkinsfile
in Git repo - Use Job DSL or JCasC (Jenkins Configuration as Code)