Can I wrap a whole stage of a declarative pipeline as groovy library function?

Viewed 1982

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?

1 Answers

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.

Related