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

Matrix: allow to use axis values from variable

    XMLWordPrintable

Details

    Description

      Please support to pass in the axis values for matrix builds via a variable.

      This would enable to calculate the stages to execute during runtime. This is often needed e.g. when in a monorepository certain stages should only be run for applications that changed in a git commit.

      See also: https://issues.jenkins-ci.org/browse/JENKINS-40986?focusedCommentId=381841&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-381841

       

      pipeline {
        environment {
           LOW_ERLANG_VER = '19.3.6.8'
           MID_ERLANG_VER = '20.3.8.24'
           HIGH_ERLANG_VER = '22.2'
        }  stages {
          // ...
          // Other stages that need the values above
          // ...
          stage("Build") {
            matrix {
              axes {
                axis {
                  name 'ERLANG_VERSION'
                  values "{$env.LOW_ERLANG_VER}", "${env.MID_ERLANG_VER}", "${env.HIGH_ERLANG_VER}"
      

      Attachments

        Activity

          bitwiseman Liam Newman added a comment -

          I agree that this would be useful, but there are some technical limitations to consider.

          The values in the matrix must be defined at or before the pipeline starts. The matrix structure including stage names needs to be constructed and immutable

          This scenarios would be possible for parameters, but would not be guaranteed safe for environment variables. It would work in the example above and as long as the environment variables are literals and are never overridden during the run.
          However, these limitations are likely to cause confusion and bad surprises.

          bitwiseman Liam Newman added a comment - I agree that this would be useful, but there are some technical limitations to consider. The values in the matrix must be defined at or before the pipeline starts. The matrix structure including stage names needs to be constructed and immutable This scenarios would be possible for parameters, but would not be guaranteed safe for environment variables. It would work in the example above and as long as the environment variables are literals and are never overridden during the run. However, these limitations are likely to cause confusion and bad surprises.
          wohali Joan Touzet added a comment - - edited

          That'd be fine by us. Could they be constants - maybe borrowing syntax from Groovy?

          final LOW_ERLANG_VER = '19.3.6.8'
          
          wohali Joan Touzet added a comment - - edited That'd be fine by us. Could they be constants - maybe borrowing syntax from Groovy? final LOW_ERLANG_VER = '19.3.6.8'

          Allowing the entire list to be specified as a build parameter would be very valuable to us.  That way, we could have an upstream job that computes the matrix axis value and passes it to the job that executes the matrix build.

          rhpatrick Robert Patrick added a comment - Allowing the entire list to be specified as a build parameter would be very valuable to us.  That way, we could have an upstream job that computes the matrix axis value and passes it to the job that executes the matrix build.

          People

            Unassigned Unassigned
            fho Fabian Holler
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated: