Declarative Pipeline with variable number of stages

50 views
Skip to first unread message

Andreas Røsdal

unread,
Dec 17, 2017, 7:32:23 AM12/17/17
to Jenkins Users
Hello,

I would like to implement a declarative pipeline in Jenkin, using only one Jenkinsfile,
but have variable number of stages depending upon which branch of the project is being built.

Is this possible? Can I dynamically change the number of stages in a dynamic pipeline?
Can I dynamically change the label text of a stage in a declarative pipeline?



Andreas

Christopher Orr

unread,
Dec 17, 2017, 7:39:22 AM12/17/17
to jenkins...@googlegroups.com
Hi there,
You can conditionally run certain stages, using the `when` directive
and the `branch` conditions:
https://jenkins.io/doc/book/pipeline/syntax/#when
https://youtu.be/YWb5Is6VwPg

I'm not sure whether you can dynamically specify a stage name, but
calling a shared library function that returns a String could
potentially work.

Regards,
Chris

Andreas Røsdal

unread,
Dec 18, 2017, 12:34:44 PM12/18/17
to Jenkins Users
On Sunday, December 17, 2017 at 1:39:22 PM UTC+1, Christopher Orr wrote:
Hi there,

On Sun, 17 Dec 2017, at 13:21, Andreas Røsdal wrote:
> I would like to implement a declarative pipeline in Jenkin, using only one Jenkinsfile,
> but have variable number of stages depending upon which branch of the project is being built.

You can conditionally run certain stages, using the `when`  directive
and the `branch` conditions:
https://jenkins.io/doc/book/pipeline/syntax/#when
https://youtu.be/YWb5Is6VwPg


When I exclude certain stages from the pipeline using the 'when' directive,
they are still included in the Jenkins pipeline stage view as having run successfully for some milliseconds,
even though they where excluded by 'when'.


Is seems like a bug in the Jenkins stage view plugin, that stages which are excluded by 'when' are still
shown as having completed successfully?


Thanks for the reply!



Regards,
Andreas
 
Reply all
Reply to author
Forward
0 new messages