Declarative Pipeline v1.4.0-beta-1 - Matrix stages

91 views
Skip to first unread message

Liam Newman

unread,
Aug 6, 2019, 4:12:32 PM8/6/19
to Jenkins Developers

Hello all!

I'm pleased to announce the release of Declarative Pipeline 1.4.0-beta-1 with Matrix Stages. This feature allows pipeline authors to specify a matrix of one or more dimensions and run a set of stages on the combination of values specified. 


One simple use case where Matrix Stages are valuable is running browser tests on several operating systems and browser combinations.  Let’s say we want to run tests on Linux, OS X, and Windows for browsers Chrome, Firefox, IE, and Safari. We’ll want to run tests for IE on Windows only and we’ll want tests for Safari to run on OS X and Windows.  Here’s what that scenario will look like using the new “matrix” directive:


Jenkinsfile

----------

pipeline {

    agent none

    stages {

        stage("foo") {

            matrix {

                axes {

                    axis {

                        name 'os'

                        values "linux", "windows", "mac"

                    }

                    axis {

                        name 'browser'

                        values "firefox", "chrome", "safari", "ie"

                    }

                }

                excludes {

                    exclude {

                        axis {

                            name 'os'

                            values 'linux'

                        }

                        axis {

                            name 'browser'

                            values 'safari'

                        }

                    }

                    exclude {

                        axis {

                            name 'os'

                            notValues 'windows'

                        }

                        axis {

                            name 'browser'

                            values 'ie'

                        }

                    }

                }

                stages {

                    stage("first") {

                        steps {

                            echo "Running on OS=$os, BROWSER=$browser"

                        }

                    }

                    stage("second") {

                        steps {

                            // ... Second stage steps ... 

                        }

                    }

                }

            }

        }

    }

}

----------


In the example, we specify two axes and the values for each of them. Then, we use the optional “excludes” directive to remove undesired combinations from the matrix. Finally, we specify one or more stages that we want to run on each combination.   


Log fragment:

[Pipeline] stage

[Pipeline] { (foo)

[Pipeline] parallel

[Pipeline] { (Branch: Matrix: os = 'linux', browser = 'firefox')

[Pipeline] { (Branch: Matrix: os = 'windows', browser = 'firefox')

[Pipeline] { (Branch: Matrix: os = 'mac', browser = 'firefox')

[Pipeline] { (Branch: Matrix: os = 'linux', browser = 'chrome')

[Pipeline] { (Branch: Matrix: os = 'windows', browser = 'chrome')

[Pipeline] { (Branch: Matrix: os = 'mac', browser = 'chrome')

[Pipeline] { (Branch: Matrix: os = 'windows', browser = 'safari')

[Pipeline] { (Branch: Matrix: os = 'mac', browser = 'safari')

[Pipeline] { (Branch: Matrix: os = 'windows', browser = 'ie')

...




Declarative Pipeline 1.4.0-beta-1 is available from the experimental update center now (https://jenkins.io/doc/developer/publishing/releasing-experimental-updates/). I look forward to hearing what you think of this feature and what you’d like to see in future updates to Declarative Pipeline. 


Thanks,

Liam Newman 

Senior Software Engineer - Pipeline


Jesse Glick

unread,
Aug 7, 2019, 4:03:13 PM8/7/19
to Jenkins Dev
On Tue, Aug 6, 2019 at 4:12 PM Liam Newman <bitwi...@gmail.com> wrote:
> exclude {
> axis {
> name 'os'
> notValues 'windows'
> }

This seems like a lot of conceptual weight for something that could
have been expressed in Scripted with a simple `if`-statement or two.
Is there some guiding principle for how much logic ought to be
expressible in Declarative?

Andrew Bayer

unread,
Aug 7, 2019, 4:13:26 PM8/7/19
to jenkin...@googlegroups.com
This is fantastic to see land - I've been dreaming of matrix in Declarative for years, so thank you, Liam, for making it happen!

A.

On Tue, Aug 6, 2019 at 4:12 PM Liam Newman <bitwi...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/78b8f8e6-b61c-49dc-ba24-9d25f0baa825%40googlegroups.com.

Firmsoil Soil

unread,
Oct 13, 2019, 11:17:26 PM10/13/19
to Jenkins Developers
Thanks very much Liam,

I will immediately try and demo this in my organization for multiple multi-platform (pun intended) use cases!

This is why I love jenkins plugins API ecosystem, it is by far the deepest and most feature rich in the CI landscape and promotes immense code reuse.

Sincerely
Firmsoil
Reply all
Reply to author
Forward
0 new messages