The inner retry(2) block retries the enclosed code up to 2 times on failure.
Step 2: Trace the count increments and errors
First run: count=1, error thrown (count<3). Retry 1: count=2, error thrown. Retry 2: count=3, no error, exits retry.
Step 3: Determine echo output
After retries, count is 3, so echo "Count is 3" runs.
Final Answer:
Count is 3 -> Option C
Quick Check:
Retry runs until count=3, then echo prints count [OK]
Hint: Count increments on each retry until no error [OK]
Common Mistakes:
Assuming retry runs only once
Thinking count resets on retry
Ignoring retry inside script block
4. You wrote this Jenkins pipeline options block:
options {
timeout(10)
retry(3)
}
But the build fails with a syntax error. What is the problem?
medium
A. timeout requires both time and unit parameters
B. retry cannot be used inside options block
C. timeout value must be a string, not a number
D. retry requires a block after the number
Solution
Step 1: Check timeout syntax requirements
The timeout option requires named parameters: time and unit.
Step 2: Identify missing parameters
Using timeout(10) alone is invalid; it must be timeout(time: 10, unit: 'MINUTES').
Final Answer:
timeout requires both time and unit parameters -> Option A
Quick Check:
Timeout needs time and unit named params [OK]
Hint: Timeout needs time and unit named parameters [OK]
Common Mistakes:
Passing only a number to timeout
Thinking retry needs a block
Confusing timeout value types
5. You want to create a Jenkins pipeline that stops if it runs longer than 2 minutes and retries the entire build up to 2 times if it fails. Which options block correctly implements this?