Jenkins Basics/Medium

Q1: Explain CI process being followed at your organization with the stages and what security tools you have implemented.

Ans: A typical CI process includes stages like code checkout, build, unit testing, integration testing, security scanning, and deployment. Security tools such as SonarQube for code quality, Checkmarx or Snyk for vulnerability scanning, and secret management integrations are implemented to ensure secure pipelines.

Q2: Where do you store secrets in Jenkins.

Ans: Secrets in Jenkins are stored in Jenkins Credentials Manager. They can be injected into pipelines using credential bindings, environment variables, or securely referenced in Jenkinsfiles without exposing them in plain text.

Q3: Suppose i want to drop a mail to my manager before doing deployment in prod and if he approves then only the pipeline should proceed.

Ans: You can implement an approval stage in Jenkins using the `input` step in the pipeline. The pipeline pauses and sends a notification (via email or chat integration). Once the manager approves, the pipeline resumes and proceeds to the deployment stage.

Q4: What is library and how to use one in your jenkins code.

Ans: A Jenkins Shared Library is a reusable set of pipeline code stored in a Git repository. It allows teams to centralize common functions and steps. In Jenkinsfile, you can load it using `@Library('library-name') _` and then call defined functions to standardize pipeline logic.

Q5: How does your Jenkins Vm deploys on EKS cluster.

Ans: The Jenkins VM uses kubectl or Helm with AWS IAM authentication to deploy workloads on the EKS cluster. The pipeline integrates AWS CLI or IAM roles to authenticate, applies Kubernetes manifests or Helm charts, and manages deployments directly from Jenkins.

Q6: Suppose I have a Java based application and i want to design a CI pipeline. Explain the tools and stages.

Ans: To do the CI setup following stages should be included: 1. Code checkout from Git. 2. Build using Maven or Gradle. 3. Unit testing with JUnit. 4. Static code analysis with SonarQube. 5. Security scanning with Snyk or Checkmarx. 6. Packaging into Docker images. 7. Push to container registry. 8. Deployment to Kubernetes/EKS. Tools include Jenkins, Maven/Gradle, SonarQube, Docker, and Helm.

Q7: Sample Jenkins pipeline for Java application.

JenkinsFile
pipeline {
  agent any
  stages {
    stage('Checkout') {
      steps { git 'https://github.com/example/java-app.git' }
    }
    stage('Build') {
      steps { sh 'mvn clean install' }
    }
    stage('Test') {
      steps { sh 'mvn test' }
    }
    stage('Code Analysis') {
      steps { sh 'mvn sonar:sonar' }
    }
    stage('Docker Build') {
      steps { sh 'docker build -t repo/java-app:latest .' }
    }
    stage('Push Image') {
      steps { sh 'docker push repo/java-app:latest' }
    }
    stage('Deploy to EKS') {
      steps { sh 'kubectl apply -f k8s/deployment.yaml' }
    }
  }
}

Q8: Pipeline fails due to SCM hook misconfiguration β€” How do you debug and fix?

Ans: When a Multibranch Pipeline fails to trigger builds after commits, check if SCM webhooks are correctly configured in GitHub/GitLab/Bitbucket. Verify Jenkins logs (`Manage Jenkins > System Log`) for webhook events. Ensure Jenkins has the correct webhook URL and that firewalls or reverse proxies are not blocking requests. Fix by re-registering the webhook, validating credentials, and confirming that Jenkins has the required permissions to access the repository.

Q9: Credential Rotation Scenario β€” How do you prevent pipeline failures when secrets change?

Ans: If credentials (like API keys or SSH tokens) are rotated, pipelines may fail due to invalid secrets. Store credentials in Jenkins Credentials Store instead of hardcoding them in Jenkinsfiles. Use `withCredentials` blocks to inject secrets dynamically. To prevent downtime, rotate credentials in Jenkins before updating external systems, and use credential IDs consistently across pipelines. In production, integrate Jenkins with secret managers (Vault, AWS Secrets Manager, Azure Key Vault) for automated rotation.

Q10: RBAC Misconfiguration β€” How do you recover when users lose access unexpectedly?

Ans: If Role-Based Access Control (RBAC) is misconfigured, users may lose access to jobs or credentials. Troubleshoot by checking `Manage Jenkins > Configure Global Security` and reviewing role assignments. Use the Matrix-based security view to confirm permissions. Recovery involves reassigning roles, restoring from backup, or using the Jenkins CLI to fix permissions. Best practice is to apply least privilege, test changes in a staging Jenkins, and use folder-level RBAC for isolation.

Q11: Pipeline stuck in 'Waiting for executor' β€” What are the possible causes?

Ans: This occurs when no executors are available to run the job. Causes include all agents being busy, node labels not matching, or resource throttling plugins blocking execution. Troubleshoot with `Manage Jenkins > Nodes` to check agent status. Fix by adding more executors, adjusting node labels, or scaling agents dynamically (via Kubernetes plugin or cloud auto-scaling). In production, monitor executor utilization and configure queue management policies.

Q12: Shared Library Update Breaks Pipelines β€” How do you mitigate risk?

Ans: When Jenkins Shared Libraries are updated, dependent pipelines may break due to API or logic changes. Troubleshoot by checking pipeline logs and library commit history. Mitigate by versioning libraries (e.g., `@Library('lib@v1.2')`) and testing changes in staging pipelines before rollout. In production, enforce semantic versioning, maintain backward compatibility, and document library changes clearly.

Q13: Builds fail due to workspace corruption β€” How do you recover?

Ans: Workspace corruption can occur due to interrupted builds, disk issues, or conflicting jobs. Symptoms include missing files or inconsistent states. Troubleshoot by deleting the workspace (`rm -rf workspace`) and letting Jenkins recreate it. Use `Clean before build` options in job configuration. In production, isolate workspaces per branch, use ephemeral agents (like Kubernetes pods), and monitor disk health to prevent recurrence.

Q14: Pipeline execution slowed down after plugin upgrade β€” How do you investigate?

Ans: Performance degradation after plugin upgrades may stem from compatibility issues or memory leaks. Troubleshoot by checking Jenkins logs for warnings, reviewing plugin versions, and monitoring JVM metrics (`Manage Jenkins > Monitoring`). Roll back the plugin if necessary, or upgrade dependent plugins. In production, test plugin upgrades in a staging Jenkins, monitor performance impact, and keep plugins updated only to stable releases.

Q15: Unauthorized image usage in Jenkins agents β€” How do you enforce compliance?

Ans: If Jenkins agents pull unauthorized Docker images, enforce compliance using Jenkins Cloud/Agent templates tied to approved registries. Configure Admission Controllers or OPA Gatekeeper in Kubernetes to block unapproved images. In Jenkins, restrict agent definitions to trusted registries and monitor logs for unauthorized pulls. Best practice is to integrate image signing (Cosign, Notary) and enforce policies at both Jenkins and cluster levels.

Q16: How do you setup multimaster setup in Jenkins

Ans: Jenkins does not natively support an active-active multi-master architecture where multiple instances write to the same data directory simultaneously. To set up a high-availability or multi-master environment, you typically use CloudBees Jenkins Enterprise (which utilizes a managed master architecture) or build an active-passive setup using an external shared filesystem (like AWS EFS or NFS) coupled with an orchestrator like Kubernetes. In a Kubernetes setup, a replica set of 1 is maintained for the passive failover, or separate specialized masters are decoupled by business units, sharing agents via a centralized network.

Q17: Suppose one master goes down how will other mater knows it.

Ans: In an automated active-passive or clustered setup, masters do not usually monitor each other directly; instead, a third-party orchestrator or a load balancer handles health checks. For example, a Kubernetes liveness probe or an AWS Application Load Balancer (ALB) health check detects that the primary instance is unresponsive. Once the health check fails, the orchestrator terminates the unhealthy instance and spins up the passive/secondary instance, mounting the same shared storage to assume control.

Q18: When we have DC DR setup for Jenkins how data is yncing between the DC and DR masters.

Ans: Data synchronization between Data Center (DC) and Disaster Recovery (DR) Jenkins masters relies on replicating the JENKINS_HOME directory. This is achieved using block-level storage replication (such as AWS EBS snapshots or SAN-to-SAN replication) or file-level asynchronous tools like rsync or Lsyncd running on a scheduled cron. For configuration-as-code setups, the job definitions and pipelines are synced continuously via a Git repository, while build histories and artifacts are offloaded and synchronized via shared object storage like AWS S3 or MinIO.

Q19: What is reverse proxy and why it is used.

Ans: A reverse proxy is a server that sits in front of backend web servers and forwards client requests to them. It is used to mask the identity and structure of internal servers, handle SSL/TLS termination to offload cryptographic overhead from the application, cache static content to improve performance, and provide a single point of entry for security hardening, rate limiting, and web application firewall (WAF) integration.

Q20: Difference between Reverse proxy and Load balancer.

Ans: While both manage incoming traffic, their primary objectives differ. A reverse proxy focuses on protecting, optimizing, and abstracting a backend server (often handling a single server or a specific application routing rule). A load balancer focuses on distribution, routing incoming traffic across a pool of multiple healthy backend servers to maximize capacity, optimize resource utilization, and prevent any single server from becoming a bottleneck.