Section A: Pipeline Design
Q1. How do you reuse pipeline code across many teams?
With a shared library: global steps in vars/, classes in src/, templates in resources/. Teams load it with @Library('lib@tag') _. Version it with tags, review changes like production code, and provide a whole-pipeline template (golden path) with options so teams are not forced to fork.
Q2. What is the difference between a trusted and an untrusted library?
Global (trusted) libraries configured by admins run outside the Groovy sandbox with full power, so their repository needs strict access control. Folder-level libraries run inside the sandbox, so teams can own them more safely.
Q3. What is CPS and why does it matter?
Pipeline Groovy runs through Continuation Passing Style so builds can pause and resume (for example across a controller restart or an input). Consequences: objects held across steps must be serializable, @NonCPS methods cannot call pipeline steps, and heavy Groovy computing is slow. Do heavy work in sh with real tools.
Q4. How do you make pipelines faster?
Parallel stages and test sharding, ephemeral agents with warm caches, shallow clones, changeset conditions in monorepos, Docker layer or BuildKit caching, a dependency proxy (Nexus/Artifactory), fail-fast ordering, and cancelling superseded builds with disableConcurrentBuilds(abortPrevious: true).
Q5. How do you handle flaky tests?
Detect them with history, quarantine them in a non-blocking job, find the root cause (timing, shared state, external services) and fix. Retry only infrastructure failures, not logic failures.
Q6. How would you design a pipeline for a monorepo?
Detect changed services with git diff or changeset, build only those in a dynamic parallel map on pod agents, build all when shared files change, run integration tests after images exist, and deploy only changed services.
Q7. Explain build once, deploy many.
Build one immutable artifact or image, give it a unique version, and promote the same artifact through dev, staging and production with only configuration changing. Rebuilding per environment can produce different binaries from the same commit.
Q8. How do you implement approvals and avoid holding executors?
Use agent none at pipeline level and place input in a stage without an agent, with a timeout and a submitter group. The wait costs no executor. Record the approver and ticket.
Section B: Kubernetes and Docker
Q1. How does the Kubernetes plugin work?
The controller talks to the Kubernetes API. For each build it creates a pod from a template (a jnlp agent container plus tool containers), the agent connects back, the build runs in containers selected with container('name'), and the pod is deleted afterwards.
Q2. How do you build Docker images inside Kubernetes agents?
Avoid mounting the host Docker socket (privileged and shared). Use Kaniko, BuildKit rootless, or Buildah in a container, or a remote builder. They build without a Docker daemon.
Q3. How do you deploy to Kubernetes from Jenkins safely?
Use helm upgrade --install --atomic --wait or kubectl rollout status with a timeout, per-environment credentials with minimal RBAC, smoke tests and automatic rollback. For stronger security use GitOps.
Q4. What is GitOps and how does Jenkins fit?
Desired state lives in a config Git repository and an in-cluster controller (Argo CD or Flux) pulls and applies it. Jenkins does CI: build, test, scan, push the image and commit the new tag to the config repo. Cluster credentials never leave the cluster and rollback is git revert.
Q5. How do you scale Jenkins?
Keep controllers for orchestration only, scale agents horizontally with ephemeral pods or cloud VMs, store artifacts externally, tune JVM and disk, discard old builds, and split into several controllers by team when one gets too large. Standardize them with JCasC.
Q6. Does Jenkins support high availability?
Open-source Jenkins runs one active controller per JENKINS_HOME. Achieve resilience with fast recovery: containerized controller, replicated or snapshotted storage, configuration in Git, stateless agents. Active/passive setups are possible if only one is ever active. Commercial products add managed HA features.
Section C: Security
Q1. How do you secure a Jenkins installation?
SSO (OIDC/SAML/LDAP) with MFA, matrix or role-based permissions with team folders, HTTPS behind a reverse proxy, zero executors on the controller, ephemeral agents, CSRF on, minimal and updated plugins, sandbox on, restricted Script Console, secrets in a vault, audit logging, backups and a patching routine.
Q2. How do you protect secrets in pipelines?
Use withCredentials or Vault, single-quoted shell strings, --password-stdin, short-lived cloud credentials through IAM roles or OIDC, secret scanning in CI and pre-commit, and never pass secrets to untrusted pull requests.
Q3. What is script approval and the Groovy sandbox?
The sandbox limits pipeline Groovy to allowed methods. Blocked methods appear in In-process Script Approval. Admins approve only what they understand; risky logic should move to a reviewed trusted library step.
Q4. How do you secure pull request builds from forks?
Treat fork code as untrusted: no credentials, no deploy stages, optionally take the Jenkinsfile from the target branch, and require approval before building external contributors.
Q5. What is the software supply chain risk in CI and how do you reduce it?
Compromised dependencies, base images, plugins or the pipeline itself. Use lock files, private proxies, pinned and scanned images, SBOMs, signed artifacts with verification at deploy time, reviews on Jenkinsfile changes, and tight access to the controller.
Q6. An API token was leaked in a build log. What do you do?
Revoke or rotate it immediately, check where and when it was used, remove the log or build, find the cause (interpolation, debug output, artifacts), fix it and add scanning to prevent a repeat. Document the incident.
Section D: Administration
Q1. What is JCasC?
Configuration as Code describes Jenkins settings (security, tools, credentials, clouds, global libraries, jobs via Job DSL) in YAML kept in Git. A new controller configures itself at startup, so changes are reviewed and recovery is fast.
Q2. How do you upgrade Jenkins safely?
Read the upgrade guide, check the Java requirement, back up JENKINS_HOME, test in a staging copy with the same plugins, enter quiet mode, upgrade, review logs, run key jobs, and keep a rollback path (old image tag and snapshot).
Q3. What do you back up?
JENKINS_HOME config files, secrets/, job definitions, nodes, users and chosen build history; skip workspaces and caches. Encrypt backups and test restores. Best of all, keep configuration and jobs as code.
Q4. How do you monitor Jenkins?
The Prometheus metrics plugin plus Grafana: queue length, executor use, node status, build duration and success rate, JVM heap and GC, disk. Add alerts, central logs and the audit trail.
Q5. Jenkins is slow. How do you investigate?
Check resources (CPU, heap and GC, disk I/O), the queue and agents, recent changes (plugin update, new job), thread dumps for blocked threads, and heavy pipelines or huge histories. Tune heap, discard old builds, move work to agents, remove unneeded plugins.
Scenario Questions
| Scenario | How to answer |
|---|---|
| Production deploy failed halfway | Stop the rollout, use the rollback path (helm rollback, rollout undo, previous tag), check health, then investigate. Explain how --atomic and smoke tests help. |
| Developers wait 40 minutes for feedback | Measure per stage, parallelize and shard tests, cache dependencies, run cheap checks first, build only changed parts, add agents. |
| The company wants to move to GitHub Actions | Move logic into scripts first, migrate one repo at a time, map concepts (agents to runners, credentials to secrets, input to environments, library to reusable workflows), run both until proven. |
| Plugin update broke many jobs | Restore the previous plugin or snapshot, post a note, move to staging-first updates with pinned versions and small batches. |
| A team needs prod deploys with approvals and audit | Promotion pipeline with input and submitters, per-environment credentials, tickets recorded, notifications, and Git history or GitOps for the audit trail. |
| Jenkins controller disk is full | Free space (old builds, workspaces), add buildDiscarder, move artifacts to a repository, expand volume, and add a disk alert. |
Practice
- Answer three scenarios with the structure: clarify, contain, fix, prevent
- Draw the architecture for a secure Kubernetes-based Jenkins on a whiteboard
- Explain one production incident you handled with Jenkins
- Be ready to write a short shared library step from memory
Conclusion
Senior answers show design thinking: shared libraries and golden paths, safe approvals, ephemeral Kubernetes agents, GitOps, layered security, JCasC and backups, scaling by splitting controllers, and a calm incident routine of clarify, contain, fix and prevent.

