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

Matrix command in Declarative Pipeline does not filter nodes correctly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • pipeline
    • Latest Jenkins with AWS ec2 plugins

      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'
                          }
                      }
      

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

              Created:
              Updated: