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

Matrix command in Declarative Pipeline does not filter nodes correctly.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Blocker
    • Resolution: Unresolved
    • Component/s: pipeline
    • Labels:
    • Environment:
      Latest Jenkins with AWS ec2 plugins
    • Similar Issues:

      Description

      I have an Jenkins with AWS integration where all the agents node are created dynamically.
      My issue is when I use the "martix" statement and use the "when" to filter OSes that are not needed to be built, the nodes are still created then skip by when statement. Is there a way to apply the "when" statement to filter so only nodes are required is created?

      Below is my pipeline code and if I shoose ubuntu platform, windows and macos node still gets created but nothing runs since its filtered by the when condition.

      pipeline {
          parameters {
              choice(name: 'PLATFORM_FILTER', choices: ['ubuntu', 'windows', 'macos', 'all'], description: 'Run on specific platform')
          }
          agent none
          stages {
              stage('CI pipeline') {
                  matrix {
                      when { anyOf {
                          expression { params.PLATFORM_FILTER == 'all' }
                          expression { params.PLATFORM_FILTER == env.PLATFORM }
                      } }
                      agent {
                          label "${PLATFORM}-agent"
                      }
                      axes {
                          axis {
                              name 'PLATFORM'
                              values 'ubuntu', 'windows', 'macos'
                          }
                      }
      

        Attachments

          Issue Links

            Activity

            Hide
            wayonb Wayon Blair added a comment -

            The reason why I but open this as a blocker is because my macos is expense and there is only one node which Its not always online.
            In this scenario the job will wait for macos node to be online just to skip it.

            This is logs below

            [Pipeline] echo
            Found Git Build Cause: commit
            [Pipeline] }
            [Pipeline] // node
            [Pipeline] stage
            [Pipeline] { (CI pipeline)
            [Pipeline] parallel
            [Pipeline] { (Branch: Matrix - PLATFORM = 'ubuntu') (hide)
            [Pipeline] { (Branch: Matrix - PLATFORM = 'windows')
            [Pipeline] stage
            [Pipeline] { (Matrix - PLATFORM = 'ubuntu')
            [Pipeline] stage
            [Pipeline] { (Matrix - PLATFORM = 'windows')
            [Pipeline] withEnv
            [Pipeline] {
            [Pipeline] withEnv
            [Pipeline] {
            [Pipeline] node
            [Pipeline] node
            Still waiting to schedule task
            All nodes of label ‘ubuntu-agent’ are offline
            Still waiting to schedule task
            All nodes of label ‘windows-agent’ are offline

            Then it would skip windows after creating the node.

            [Pipeline] withEnv
            [Pipeline]

            { [Pipeline] }

            [Pipeline] // withEnv
            [Pipeline] }
            [Pipeline] // node
            Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional
            [Pipeline] stage
            [Pipeline]

            { (checkout) Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional [Pipeline] }

            [Pipeline] // stage
            [Pipeline] stage
            [Pipeline]

            { (verify conventional commit message) Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional [Pipeline] }
            Show
            wayonb Wayon Blair added a comment - The reason why I but open this as a blocker is because my macos is expense and there is only one node which Its not always online. In this scenario the job will wait for macos node to be online just to skip it. This is logs below [Pipeline] echo Found Git Build Cause: commit [Pipeline] } [Pipeline] // node [Pipeline] stage [Pipeline] { (CI pipeline) [Pipeline] parallel [Pipeline] { (Branch: Matrix - PLATFORM = 'ubuntu') (hide) [Pipeline] { (Branch: Matrix - PLATFORM = 'windows') [Pipeline] stage [Pipeline] { (Matrix - PLATFORM = 'ubuntu') [Pipeline] stage [Pipeline] { (Matrix - PLATFORM = 'windows') [Pipeline] withEnv [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] node [Pipeline] node Still waiting to schedule task All nodes of label ‘ubuntu-agent’ are offline Still waiting to schedule task All nodes of label ‘windows-agent’ are offline Then it would skip windows after creating the node. [Pipeline] withEnv [Pipeline] { [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional [Pipeline] stage [Pipeline] { (checkout) Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (verify conventional commit message) Stage "Matrix - PLATFORM = 'windows'" skipped due to when conditional [Pipeline] }
            Hide
            kon Kalle Niemitalo added a comment -

            Perhaps beforeAgent true would do what you want. See JENKINS-44461 and Evaluating when before entering agent in a stage.

            Show
            kon Kalle Niemitalo added a comment - Perhaps beforeAgent true would do what you want. See JENKINS-44461 and Evaluating when before entering agent in a stage .

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              wayonb Wayon Blair
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: