What is a Jenkins agent label, and how do you target specific agents?
CI/CD & GitOps · Basic level
Answer
A Jenkins agent label is metadata used to select where a build runs. A pipeline can target an agent label such as linux, docker, gpu, arm64, or k8s so the job runs only on workers with the required OS, tools, network access, or hardware.
Technical explanation
Keep build execution away from the controller; agents should be disposable, labeled, and sized for the workload.
Treat the pipeline definition as production code: peer review it, test changes, version shared libraries, and avoid hidden UI-only job logic.
Use least-privilege credentials, immutable artifacts, deterministic versions, and clear post-build cleanup to make pipelines repeatable and auditable.
Design stages around fast feedback: fail cheap checks early, isolate workspaces, parallelize independent work, and publish evidence such as test reports and build metadata.
Hands-on example
1. Create or update a Jenkinsfile for the scenario: What is a Jenkins agent label, and how do you target specific agents.
2. Use a Declarative Pipeline skeleton: pipeline { agent { label 'linux && docker' } options { timestamps(); disableConcurrentBuilds() } stages { stage('Checkout') { steps { checkout scm } } stage('Test') { parallel { stage('Unit') { steps { sh 'make unit' } } stage('Lint') { steps { sh 'make lint' } } } } } post { always { junit 'reports/*.xml'; cleanWs() } failure { echo 'notify team' } } }.
3. Inject secrets only in the narrowest stage, for example withCredentials([string(credentialsId: 'scanner-token', variable: 'TOKEN')]) { sh 'scanner --fail-on critical' }; do not echo TOKEN or write it into archived artifacts.
4. Publish the immutable result: tag the image with the Git SHA, push to ECR/Nexus, archive test reports, and record build URL, commit SHA, artifact digest, approver, and deployment status.
5. Prove the design by rerunning the same commit twice: the second run should reuse safe caches, produce the same artifact version or detect it already exists, and avoid duplicate side effects.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More CI/CD & GitOps interview questions
- How would you reduce the run time of a slow pipeline?
- How do you handle build artifacts and where do you store them (Nexus, ECR)?
- How do you cache dependencies to speed up Jenkins builds?
- What is the difference between archiving artifacts and publishing to a registry?
- How would you fail a build when a security scan finds a critical vulnerability?
- How do you keep a pipeline idempotent and safely re-runnable?
- How do you implement an approval/manual gate before a production deploy?
- How do you implement blue-green or canary deployment from a pipeline?