0
0
Jenkinsdevops~20 mins

Matrix builds for multi-platform in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Build Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a Jenkins matrix build with two platforms
Given the following Jenkins pipeline snippet, what will be the output printed for the PLATFORM variable during the build?
Jenkins
pipeline {
  agent none
  stages {
    stage('Build') {
      matrix {
        axes {
          axis {
            name 'PLATFORM'
            values 'linux', 'windows'
          }
        }
        stages {
          stage('Print Platform') {
            agent any
            steps {
              echo "Building on ${PLATFORM}"
            }
          }
        }
      }
    }
  }
}
ABuilding on linux\nBuilding on windows
BBuilding on linux
CBuilding on windows
DBuilding on linux\nBuilding on linux
Attempts:
2 left
💡 Hint
Think about how matrix axes create parallel builds for each value.
Configuration
intermediate
2:00remaining
Correct matrix axis syntax for multi-platform builds
Which of the following Jenkins pipeline matrix axis configurations correctly defines a multi-platform build for 'linux' and 'mac'?
A
axis {
  name: 'PLATFORM'
  values: ['linux', 'mac']
}
B
axis {
  name = 'PLATFORM'
  values = ['linux', 'mac']
}
C
axis {
  name 'PLATFORM'
  values 'linux', 'mac'
}
D
axis {
  PLATFORM = ['linux', 'mac']
}
Attempts:
2 left
💡 Hint
Jenkins pipeline uses Groovy syntax without equals or colons in this context.
Troubleshoot
advanced
2:00remaining
Why does the Jenkins matrix build fail with 'No agent specified' error?
Consider this Jenkins pipeline snippet: pipeline { agent none stages { stage('Build') { matrix { axes { axis { name 'OS' values 'linux', 'windows' } } stages { stage('Compile') { steps { echo "Compiling on ${OS}" } } } } } } } Why does this pipeline fail with a 'No agent specified' error?
ABecause the 'echo' step is not allowed inside matrix stages.
BBecause the matrix axis name 'OS' is invalid and causes the build to fail.
CBecause the 'matrix' block requires an 'agent any' declaration at the top level.
DBecause the 'Compile' stage inside matrix does not specify an agent, and the parent agent is 'none'.
Attempts:
2 left
💡 Hint
Remember that each stage needs an agent unless inherited from parent.
🔀 Workflow
advanced
3:00remaining
Matrix build with environment variables per platform
You want to run a Jenkins matrix build for platforms 'linux' and 'windows'. For 'windows', you need to set an environment variable WIN_PATH to C:\\Build. Which pipeline snippet correctly sets this environment variable only for the windows build?
A
matrix {
  axes {
    axis {
      name 'PLATFORM'
      values 'linux', 'windows'
    }
  }
  stages {
    stage('Build') {
      steps {
        script {
          if (PLATFORM == 'windows') {
            env.WIN_PATH = 'C:\\Build'
          }
          echo "Platform: ${PLATFORM}, Path: ${env.WIN_PATH}"
        }
      }
    }
  }
}
B
matrix {
  axes {
    axis {
      name 'PLATFORM'
      values 'linux', 'windows'
    }
  }
  stages {
    stage('Build') {
      environment {
        WIN_PATH = 'C:\\Build'
      }
      steps {
        echo "Platform: ${PLATFORM}, Path: ${WIN_PATH}"
      }
    }
  }
}
C
matrix {
  axes {
    axis {
      name 'PLATFORM'
      values 'linux', 'windows'
    }
  }
  environment {
    WIN_PATH = 'C:\\Build'
  }
  stages {
    stage('Build') {
      steps {
        echo "Platform: ${PLATFORM}, Path: ${WIN_PATH}"
      }
    }
  }
}
D
matrix {
  axes {
    axis {
      name 'PLATFORM'
      values 'linux', 'windows'
    }
  }
  stages {
    stage('Build') {
      steps {
        echo "Platform: ${PLATFORM}, Path: ${WIN_PATH}"
      }
    }
  }
  environment {
    WIN_PATH = 'C:\\Build'
  }
}
Attempts:
2 left
💡 Hint
Environment variables can be set dynamically inside a script block.
Best Practice
expert
3:00remaining
Optimizing Jenkins matrix builds for resource usage
You have a Jenkins matrix build with 3 axes: OS (linux, windows), JDK (8, 11), and DB (mysql, postgres). This creates 12 parallel builds. Your Jenkins server has limited executors. What is the best way to optimize resource usage without losing coverage?
AUse the 'failFast true' option in the matrix to stop all builds if one fails, saving resources.
BUse the 'maxParallel' option to limit the number of concurrent builds running at once.
CReduce the number of axes values by removing less important combinations to lower total builds.
DRun all builds sequentially by setting 'parallel false' to avoid overloading executors.
Attempts:
2 left
💡 Hint
Think about controlling concurrency rather than removing coverage or running sequentially.