I would like to add something like
myStage()
to a Jenkinsfile. myStage()
is defined in a shared library and contains a whole stage. Is this possible? I read that I can put individual steps and whole pipelines into groovy functions, but are stages possible as well?
The top-level of the Pipeline must be a block, specifically: pipeline { } No semicolons as statement separators. Each statement has to be on its own line. Blocks must only consist of declarative sections, declarative directives, declarative steps, or assignment statements.
Basically, declarative and scripted pipelines differ in terms of the programmatic approach. One uses a declarative programming model and the second uses an imperative programming mode. Declarative pipelines break down stages into multiple steps, while in scripted pipelines there is no need for this.
Since Jenkins are now allowing nested stages, you can put a stages into a stage to make nested level of stages.
It's not possible for declarative pipelines.
Other parts of a declarative pipeline might be extensible through libraries, like options
, but it was said that:
For example, anything that contains an actual step execution (so steps, post, when (in part because of when expression and in part because it'd be a pain in the ass), stage, and stages (because stage contains steps and stages contains stage) would not be supported.
See https://issues.jenkins-ci.org/browse/JENKINS-49135.
Also, entire pipelines in libraries is officially supported since Declarative Pipeline 1.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With