Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-64949

Declarative Pipeline: Allow defining matrix axes from a file or a variable

XMLWordPrintable

      As a Jenkins user writing pipelines from my projects,
      When I use a matrix in Declarative syntax because this syntax is really efficient and easy to read and maintain
      Then I would want to allow defining dynamically some axis from a file content and/or a variable defined outside the scope of the pipeline block

      Examples of the expectations (that are only suggestions):

      pipeline {
        // ..
        stages {
          stage("Build") {
            matrix {
              axes {
                axis {
                  name 'GOARCH'
                  values readYaml file: 'archs.yml'
                }
      // ...
      

      with the following file:

      # archs.yml
      - amd64
      - i368
      - s390x
      
      //...
                axis {
                  name 'GOARCH'
                  values readJson file: 'archs.json'
                }
      //...
      
      ["amd64", "i386","s390x"]
      
      • Eventually with a dumb text file with 1 value per line:
      //...
                axis {
                  name 'GOARCH'
                  values readTxt file: 'archs.txt
                }
      //...
      
      amd64
      i386
      s390x
      
      • Or from a variable defined outside the `pipeline {}` block:
      def architectureList = readYaml file: "archs.yaml"
      
      pipeline {
      //...
         axis { 
           name 'GOARCH' 
           values architectureList
        }
      

      Of course, the scripted syntax solves this issue, but the cost of switching syntax is high (not mentioning that it does not fit all the pipeline writers).

      Inspiration come from https://github.blog/changelog/2020-04-15-github-actions-new-workflow-features/#new-fromjson-method-in-expressions.

      It's interesting how CDS and Gitlab are "solving" the dynamic matrix issue by using "templates" that generate sub pipelines for each matrix axe: https://ovh.github.io/cds/docs/concepts/template/ and https://gitlab.com/gitlab-com/www-gitlab-com/-/merge_requests/45795/diffs.

            Unassigned Unassigned
            dduportal Damien Duportal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: