Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 518
J Fabian Meier Avatar asked Nov 27 '17 15:11

J Fabian Meier


People also ask

What block can be used to control if a stage runs in a declarative pipeline?

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.

Which is better scripted or declarative pipeline?

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.

Can you have a stage within a stage Jenkins?

Since Jenkins are now allowing nested stages, you can put a stages into a stage to make nested level of stages.


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.

like image 197
Leandro Lucarella Avatar answered Sep 28 '22 09:09

Leandro Lucarella