Interview Prep/Jenkins/Jenkinsfile syntax, Groovy & CPS errors

A `when { branch 'main' }` stage is always skipped, even on main. The job is a plain Pipeline, not multibranch.

IntermediateTroubleshootingJenkinsfile syntax, Groovy & CPS errors
Answer

Likely causes → branch condition reads BRANCH_NAME, which only multibranch jobs set. Plain Pipeline jobs don't have it (GIT_BRANCH is origin/main).

Diagnose →

sh 'env | sort | grep -E "BRANCH|GIT_"'

Fix → Convert to multibranch (recommended), or use when { expression { env.GIT_BRANCH == 'origin/main' } }.

Prevent → Use multibranch for any repo-driven pipeline.

All Jenkins questions Roadmap: Jenkins

More on Jenkinsfile syntax, Groovy & CPS errors