4. You have a Jenkins pipeline that runs slowly. Which change will help fix this issue?
stage('Build') {
steps {
sh 'sleep 60'
}
}
medium
A. Add more sleep commands to wait longer
B. Increase the timeout to 120 minutes
C. Change sleep to a non-blocking command
D. Remove the sleep command or reduce its duration
Solution
Step 1: Identify slow step
The 'sleep 60' command pauses the pipeline for 60 seconds, slowing it down.
Step 2: Fix by removing or reducing sleep
Removing or reducing sleep will speed up the pipeline.
Final Answer:
Remove the sleep command or reduce its duration -> Option D
Quick Check:
Removing delays = faster pipeline [OK]
Hint: Remove unnecessary waits like sleep to speed up pipelines [OK]
Common Mistakes:
Adding more sleep commands
Increasing timeout instead of fixing delay
Thinking sleep is non-blocking
5. You want to speed up a Jenkins pipeline by skipping tests when a commit message contains '[skip tests]'. Which pipeline step correctly implements this logic?
hard
A. if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { sh 'run-tests.sh' } else { echo 'Skipping tests' }
B. if (env.GIT_COMMIT_MESSAGE == '[skip tests]') { sh 'run-tests.sh' } else { echo 'Skipping tests' }
C. if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' }
D. if (env.GIT_COMMIT_MESSAGE.contains('skip tests')) { sh 'run-tests.sh' } else { echo 'Skipping tests' }
Solution
Step 1: Understand the condition to skip tests
Tests should be skipped if commit message contains '[skip tests]'.
Step 2: Match correct logic and commands
if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } checks for '[skip tests]' and skips tests by echoing message; else runs tests.
Final Answer:
if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } -> Option C
Quick Check:
Correct condition and action = if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } [OK]
Hint: Use contains('[skip tests]') to conditionally skip tests [OK]
Common Mistakes:
Using equality instead of contains
Reversing the if-else logic
Missing brackets in string match
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.