Overview - Stage conditions with when directive
What is it?
In Jenkins pipelines, the 'when' directive controls whether a stage runs or not based on specific conditions. It lets you decide if a stage should execute depending on things like branch name, environment variables, or build status. This helps make pipelines smarter and more efficient by skipping unnecessary steps. Without it, every stage would run every time, wasting time and resources.
Why it matters
The 'when' directive exists to save time and resources by running only the necessary parts of a pipeline. Without it, pipelines would always run all stages, even when some are irrelevant, causing longer build times and wasted compute power. This can slow down development and increase costs, especially in large projects with many stages.
Where it fits
Before learning 'when' conditions, you should understand basic Jenkins pipeline syntax and stages. After mastering 'when', you can explore advanced pipeline features like parallel stages, scripted pipelines, and shared libraries to build more complex automation.