I've seen this mentioned several times in other tickets and websites, but I was unable to find a ticket that specifically addresses it. (So hopefully I didn't just simply miss it)
Problem: Given several different repositories, with different branches that do different stages, there is no simple way to modify a pipeline based on some configuration in order to keep declarative pipelines DRY.
- Branch 1 stages: A -> B -> C
- Branch 2 stages: A -> B -> D
- Branch 3 stages: A -> B -> C -> D
Currently, that requires defining 3 different pipelines, which means redundant code exists in different files and in turn increases the potential for errors to occur. In more complex situations, the ability to review changes to all the different combinations of pipelines is simply not possible.
Using "when" in stages is a workaround to this problem, but that causes confusion for developers who see a "Deploy" stage in a branch build that should not be deploying, for example. Also, for complicated scenarios, there could be many skipped stages that will always be skipped and simply add unnecessary verbosity to the visualization.
The other workaround is to use scripted pipelines, but many of the visualization features provided by using declarative don't exist or don't work correctly all the time. Also, since the list of stages are not determined up-front, the stage view always resets during a build.
There are 2 solutions that I can think of:
- Provide the ability to modify the "when" behavior, so that blue ocean visualization completely ignores it. The problem with this approach is that the "when" condition, I believe, is evaluated when executing the stage, but the list of stages is determined in the beginning at the time the pipeline is evaluated. It's possible that this could actually be implemented though to simply hide the stage in the visualizations rather than ignore it completely. For example: (This can probably be greatly improved upon, but it shows the point):
- Add another directive that is evaluated up-front to determine the stage list. If the list of stages changes from build to build, it would be no different than if the entire declarative pipeline changed and different stages existed. For example: