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.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner