Interview Prep/CI/CD/Jenkins Pipelines and Agents

You must send a Slack notification and clean the workspace whether the build passes or fails. Where does that go?

BeginnerScenarioJenkins Pipelines and Agents
Answer

Situation read → Cleanup and notification must be unconditional.

What I'd do →

post {
  always  { junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml' }
  failure { slackSend channel: '#ci', message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}" }
  cleanup { cleanWs() }
}

Why → post conditions run after stages regardless of result, and cleanup runs last, after all other post conditions.

Interview tip → Know the order: always, then changed/fixed/regression, then success/failure, then cleanup.

All CI/CD questions

More on Jenkins Pipelines and Agents