A. Fails with a syntax error due to missing parameters
B. Prints the workspace contents without deleting anything
C. Archives the workspace files for later use
D. Deletes all files in the current workspace before the build
Solution
Step 1: Analyze the cleanWs() step in the pipeline
The cleanWs() step deletes all files in the current workspace.
Step 2: Understand the pipeline effect
Since it is in the 'Clean' stage, it removes workspace files before further build steps.
Final Answer:
Deletes all files in the current workspace before the build -> Option D
Quick Check:
cleanWs() deletes workspace files [OK]
Hint: cleanWs() deletes workspace files, no parameters needed [OK]
Common Mistakes:
Thinking cleanWs() only lists files
Assuming cleanWs() needs parameters
Confusing cleanWs() with archiving
4. You added cleanWs() in your Jenkins Pipeline, but the workspace is not cleaned. What is a likely cause?
medium
A. cleanWs() only cleans after the build, not before
B. cleanWs() requires additional parameters to work
C. The pipeline is running on a shared agent and workspace cleanup is disabled
D. The Jenkins server needs a restart to apply cleanWs()
Solution
Step 1: Understand workspace cleanup behavior on shared agents
On shared agents, workspace cleanup may be disabled or restricted to avoid deleting others' files.
Step 2: Check common misunderstandings about cleanWs()
cleanWs() works without parameters and cleans immediately; server restart is not needed.
Final Answer:
The pipeline is running on a shared agent and workspace cleanup is disabled -> Option C
Quick Check:
Shared agent restrictions block cleanWs() [OK]
Hint: Check agent type; shared agents may block cleanup [OK]
Common Mistakes:
Thinking cleanWs() needs parameters
Assuming cleanup only happens after build
Restarting Jenkins unnecessarily
5. You want to ensure your Jenkins Pipeline cleans the workspace only after a successful build to save disk space but keep files if the build fails. How can you achieve this?
hard
A. Use post { success { cleanWs() } } block in the pipeline
B. Call cleanWs() at the start of the pipeline
C. Add cleanWs() inside the always post block
D. Configure Jenkins global settings to clean workspace on failure
Solution
Step 1: Understand Jenkins post-build actions
The post block allows running steps based on build result, like success.
Step 2: Use conditional cleanup after successful build
Placing cleanWs() inside post { success { ... } } cleans workspace only if build succeeds.
Final Answer:
Use post { success { cleanWs() } } block in the pipeline -> Option A
Quick Check:
Post success block cleans workspace conditionally [OK]
Hint: Use post { success { cleanWs() } } to clean only on success [OK]
Common Mistakes:
Cleaning workspace at start loses files before build
Using always block cleans even on failure
Expecting global settings to handle conditional cleanup
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.