Interview Prep/CI/CD/Jenkins Pipelines and Agents

Builds fail occasionally because the workspace has leftovers from earlier runs. What do you do?

BeginnerScenarioJenkins Pipelines and Agents
Answer

Situation read → Stale files in a reused workspace.

What I'd do →

  1. Use cleanWs() in post { cleanup { } }, or options { skipDefaultCheckout() } plus checkout scm with CleanBeforeCheckout.
  2. Prefer ephemeral agents so the workspace is born clean.
  3. Never rely on files left in target/ to make a build pass.

Why → Clean builds prove the pipeline is self-contained.

Interview tip → Cleaning costs cache hits; trade it off with a proper dependency cache.

All CI/CD questions

More on Jenkins Pipelines and Agents