Can a Jenkins agent have multiple labels? Why is this useful?
Yes, an agent can have multiple labels. This allows flexible job assignment because jobs can request any one of the labels that match the agent's capabilities.
Click to reveal answer
What is the main use of labels in Jenkins agent selection?
ATo configure Jenkins plugins
BTo name the Jenkins job
CTo set job build triggers
DTo identify which agent should run a job
✗ Incorrect
Labels help Jenkins pick the right agent to run a job based on matching labels.
Where do you assign labels to a Jenkins agent?
AIn the Jenkins system logs
BIn the Jenkins global settings
CIn the agent's configuration page
DInside the job's build steps
✗ Incorrect
Labels are assigned on the agent's configuration page to describe its capabilities.
What happens if no agent matches the label specified in a Jenkins job?
AThe job waits in the queue until an agent is available
BThe job runs on the master node
CThe job is canceled automatically
DThe job runs on any available agent
✗ Incorrect
The job waits in the queue until an agent with the matching label is free.
How do you specify an agent label in a Jenkins Pipeline script?
Aagent { label 'labelName' }
Bnode('labelName') { }
Cstage('labelName') { }
Dbuild('labelName')
✗ Incorrect
The 'agent' directive with 'label' specifies which agent label to use in a pipeline.
Why might an agent have multiple labels?
ATo confuse Jenkins
BTo allow jobs with different label requirements to run on it
CTo increase build speed
DTo reduce disk space usage
✗ Incorrect
Multiple labels let an agent serve different types of jobs by matching various label requests.
Explain how Jenkins uses labels to select agents for running jobs.
Think about how Jenkins finds the right worker for a task.
You got /4 concepts.
Describe how to assign and use labels in a Jenkins Pipeline script.
Focus on both the agent setup and pipeline syntax.
You got /3 concepts.
Practice
(1/5)
1.
What is the main purpose of using labels in Jenkins agent selection?
easy
A. To store job build logs
B. To change the Jenkins user interface theme
C. To tell Jenkins which agent can run a specific job
D. To configure Jenkins system settings
Solution
Step 1: Understand Jenkins agent labels
Labels are tags assigned to agents to identify their capabilities or roles.
Step 2: Purpose of labels in job assignment
Jenkins uses these labels to select the right agent that matches the job requirements.
Final Answer:
To tell Jenkins which agent can run a specific job -> Option C
Quick Check:
Labels guide agent selection = A [OK]
Hint: Labels connect jobs to suitable agents quickly [OK]
Common Mistakes:
Thinking labels change UI or store logs
Confusing labels with system settings
2.
Which of the following is the correct syntax to select an agent with label linux and docker in Jenkins pipeline?
easy
A. agent { label linux docker }
B. agent { label 'linux, docker' }
C. agent { label 'linux || docker' }
D. agent { label 'linux && docker' }
Solution
Step 1: Understand label expressions in Jenkins
Jenkins uses logical operators like && for AND and || for OR in label expressions.
Step 2: Correct syntax for AND condition
To require both labels, use 'linux && docker' inside the label field.
Final Answer:
agent { label 'linux && docker' } -> Option D
Quick Check:
AND labels use && = D [OK]
Hint: Use && for AND, || for OR in label expressions [OK]
Common Mistakes:
Using space-separated labels without operators
Using commas instead of logical operators
Confusing AND (&&) with OR (||)
3.
Given this Jenkins pipeline snippet, what agent will run the job if agents have labels linux, docker, and gpu?
agent { label 'linux && (docker || gpu)' }
medium
A. An agent with linux and either docker or gpu labels
B. An agent with linux and gpu labels
C. An agent with both linux and docker labels
D. Any agent with linux, docker, and gpu labels all together
Solution
Step 1: Analyze label expression
The expression requires the agent to have the 'linux' label AND either 'docker' OR 'gpu' label.
Step 2: Determine matching agents
Agents with 'linux' plus 'docker' or 'linux' plus 'gpu' satisfy the condition.
Final Answer:
An agent with linux and either docker or gpu labels -> Option A
Quick Check:
linux AND (docker OR gpu) = A [OK]
Hint: Parentheses group OR conditions, AND applies outside [OK]
Common Mistakes:
Thinking all three labels are required
Ignoring parentheses in label expressions
Assuming OR means both labels must be present
4.
What is wrong with this Jenkins pipeline agent label expression that causes the job to wait indefinitely?
agent { label 'linux && docker || gpu' }
medium
A. Labels must be quoted with double quotes, not single quotes
B. Missing parentheses causing wrong operator precedence
C. Using commas instead of logical operators
D. Agent label cannot contain logical operators
Solution
Step 1: Understand operator precedence in label expressions
Logical AND (&&) has higher precedence than OR (||), so expression is parsed as '(linux && docker) || gpu'.
Step 2: Identify why job waits
If no agent has both linux and docker, but some have gpu alone, job may pick gpu agents. If gpu agents are missing or busy, job waits.
Final Answer:
Missing parentheses causing wrong operator precedence -> Option B
Quick Check:
Use parentheses to control label logic = C [OK]
Hint: Use parentheses to clarify label logic precedence [OK]
Common Mistakes:
Ignoring operator precedence in label expressions
Using wrong quote types
Believing logical operators are not allowed
5.
You want a Jenkins job to run only on agents that have linux and docker labels but never on agents with gpu label. Which label expression should you use?
hard
A. linux && docker && !gpu
B. linux && docker || !gpu
C. linux && (docker || !gpu)
D. linux && docker && gpu
Solution
Step 1: Understand label requirements
The job must run on agents with both 'linux' and 'docker' labels, but exclude any with 'gpu'.
Step 2: Construct correct label expression
Use AND (&&) for required labels and NOT (!) to exclude 'gpu': 'linux && docker && !gpu'.
Final Answer:
linux && docker && !gpu -> Option A
Quick Check:
Include linux and docker, exclude gpu = B [OK]
Hint: Use ! to exclude labels in Jenkins expressions [OK]
Common Mistakes:
Using OR instead of AND for required labels
Not excluding gpu label properly
Misplacing parentheses causing wrong logic
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.