Introduction
Sometimes you want parts of your Jenkins pipeline to run only if certain things are true. The when directive helps you decide if a stage should run or be skipped based on conditions.
When you want to run tests only on the main branch but skip on others
When you want to deploy only if the build was successful
When you want to run a stage only during working hours
When you want to skip a stage if a certain file hasn't changed
When you want to run a stage only if an environment variable has a specific value