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)

  1. 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 change HTTP_PORT=8081.
    • Restart Jenkins: sudo systemctl restart jenkins
  2. 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
  3. Scenario: Create users Devops and Testing 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”
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. Scenario: How do you configure Jenkins job for scheduled builds?

  • Use “Build periodically” option and define cron syntax (e.g., @daily, H 0 * * *)
  1. Scenario: You need to automate Jenkins backup using a shell script. What files do you back up?
  • Backup /var/lib/jenkins/, especially jobs/, plugins/, secrets/, and config.xml
  1. 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
  1. Scenario: What is the purpose of the ThinBackup or RethinBackup plugin?
  • Automates job and config backups with scheduling, retention, and restore options
  1. 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
  1. Scenario: What Jenkins plugin allows you to manage fine-grained access control for different users?
  • Role-Based Strategy Plugin
  1. 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'
  1. Scenario: What is a safe way to update Jenkins plugins and core?
  • Use “Manage Jenkins → Plugins”, check compatibility
  • Always take backup before update
  1. 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
  1. 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
  1. Scenario: You want to notify developers on job status. How do you implement this?
  • Use Email-ext plugin or integrate with Slack/MS Teams
  1. Scenario: Jenkins is throwing 'Permission denied' when accessing Git repo. What are the causes?
  • Incorrect SSH permissions or missing credentials in Jenkins
  1. Scenario: How do you secure credentials in Jenkins Pipeline?
  • Use withCredentials() block with credentials stored in Jenkins credentials manager
  1. Scenario: How do you handle secrets securely in Jenkins pipelines?
  • Use Jenkins credentials binding plugin and avoid echoing secrets in console
  1. 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
  1. Scenario: Jenkins pipeline is failing due to environment mismatch. How do you ensure consistency?
  • Use Docker agents or configure consistent slave environments
  1. 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
  1. Scenario: How do you configure Jenkins for CI/CD in a microservice-based repo?
  • Use multibranch pipelines
  • Dynamically detect services using Jenkinsfiles in subdirectories
  1. Scenario: Jenkins restart loses config. How do you prevent it?
  • Ensure persistent volume for /var/lib/jenkins in Docker or VM setup
  1. Scenario: Restore Jenkins to a specific point after job misconfiguration.
  • Use backup snapshot or GitOps-managed Jenkins configuration
  1. 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)