If agent1 is offline, what will happen when this pipeline runs?
medium
A. The pipeline will fail immediately with an error.
B. The pipeline will run on the master node instead.
C. The pipeline will wait until agent1 comes online.
D. The pipeline will skip the node block and continue.
Solution
Step 1: Understand node block behavior
The node('agent1') block waits for the specified agent to be available before running.
Step 2: Check what happens if agent is offline
If agent1 is offline, Jenkins will wait until it comes online or timeout occurs.
Final Answer:
The pipeline will wait until agent1 comes online. -> Option C
Quick Check:
node waits for agent online [OK]
Hint: node waits for specified agent to be online [OK]
Common Mistakes:
Assuming pipeline fails immediately
Thinking it runs on master automatically
Believing it skips the node block
4. You have a Jenkins agent that should be offline for maintenance, but jobs are still assigned to it. What is the most likely cause?
medium
A. The agent was not properly marked offline in Jenkins configuration.
B. The agent is offline but Jenkins is ignoring the status due to a plugin bug.
C. The agent was marked offline but the 'Accept tasks' option is still enabled.
D. The jobs are configured to run only on the master node.
Solution
Step 1: Check agent offline marking
If jobs are still assigned, likely the agent was not properly marked offline in Jenkins UI or configuration.
Step 2: Eliminate other causes
The agent was marked offline but the 'Accept tasks' option is still enabled. is incorrect because offline agents do not accept tasks; The agent is offline but Jenkins is ignoring the status due to a plugin bug. is rare; The jobs are configured to run only on the master node. is unrelated.
Final Answer:
The agent was not properly marked offline in Jenkins configuration. -> Option A
Quick Check:
Proper offline marking stops job assignment [OK]
Hint: Ensure agent is correctly marked offline in Jenkins UI [OK]
Common Mistakes:
Assuming offline agent still accepts tasks
Blaming plugins without checking config
Confusing job node assignment
5. You want to create a Jenkins pipeline that automatically skips running on an agent if it is offline and instead runs on the master node. Which scripted pipeline snippet achieves this?
hard
A. if (Jenkins.instance.getNode('agent1').toComputer().isOnline()) {
node('agent1') { echo 'Running on agent1' }
} else {
node('master') { echo 'Running on master' }
}
B. node('agent1') {
if (agent1.isOnline()) {
echo 'Running on agent1'
} else {
node('master') { echo 'Running on master' }
}
}
C. try {
node('agent1') { echo 'Running on agent1' }
} catch (Exception e) {
node('master') { echo 'Running on master' }
}
D. node('agent1') {
echo 'Running on agent1'
}
node('master') {
echo 'Running on master'
}
Solution
Step 1: Check agent online status in pipeline
if (Jenkins.instance.getNode('agent1').toComputer().isOnline()) {
node('agent1') { echo 'Running on agent1' }
} else {
node('master') { echo 'Running on master' }
} correctly checks if 'agent1' is online using Jenkins API before choosing node.
Step 2: Verify fallback to master node
If agent1 is offline, if (Jenkins.instance.getNode('agent1').toComputer().isOnline()) {
node('agent1') { echo 'Running on agent1' }
} else {
node('master') { echo 'Running on master' }
} runs the job on 'master' node, matching the requirement.
Step 3: Analyze other options
node('agent1') {
if (agent1.isOnline()) {
echo 'Running on agent1'
} else {
node('master') { echo 'Running on master' }
}
} uses invalid syntax; try {
node('agent1') { echo 'Running on agent1' }
} catch (Exception e) {
node('master') { echo 'Running on master' }
} relies on exception which is not best practice; node('agent1') {
echo 'Running on agent1'
}
node('master') {
echo 'Running on master'
} runs both nodes unconditionally.
Final Answer:
if (Jenkins.instance.getNode('agent1').toComputer().isOnline()) {
node('agent1') { echo 'Running on agent1' }
} else {
node('master') { echo 'Running on master' }
} -> Option A
Quick Check:
Check agent online status before node selection [OK]
Hint: Check agent online status via Jenkins API before node [OK]
Common Mistakes:
Using invalid syntax to check agent status
Relying on exceptions to handle offline agents
Running both nodes regardless of status
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.