Bird
Raised Fist0
Jenkinsdevops~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using a matrix build in Jenkins for multi-platform projects?
easy
A. To run the same build steps on multiple platform combinations automatically
B. To run only one build on a single platform
C. To manually select which platform to build on
D. To speed up builds by skipping tests

Solution

  1. Step 1: Understand matrix build concept

    A matrix build runs the same steps on different combinations of variables like OS and architecture.
  2. Step 2: Identify the purpose for multi-platform

    This allows testing and building on all required platforms automatically without manual intervention.
  3. Final Answer:

    To run the same build steps on multiple platform combinations automatically -> Option A
  4. Quick Check:

    Matrix build = multi-platform automatic runs [OK]
Hint: Matrix builds run all platform combos automatically [OK]
Common Mistakes:
  • Thinking matrix builds run only on one platform
  • Confusing matrix with manual selection
  • Assuming matrix skips tests
2. Which syntax correctly defines two axes named os and arch in a Jenkins matrix build?
easy
A. matrix { axis name='os' values='linux,windows'; axis name='arch' values='x86,arm' }
B. matrix { os: ['linux', 'windows'], arch: ['x86', 'arm'] }
C. axes { axis('os', ['linux', 'windows']); axis('arch', ['x86', 'arm']) }
D. axes { axis { name 'os'; values 'linux', 'windows' } axis { name 'arch'; values 'x86', 'arm' } }

Solution

  1. Step 1: Recall Jenkins matrix axes syntax

    Jenkins uses axes { axis { name '...' ; values '...' } } blocks to define axes.
  2. Step 2: Match syntax with options

    axes { axis { name 'os'; values 'linux', 'windows' } axis { name 'arch'; values 'x86', 'arm' } } matches the correct syntax with two axis blocks inside axes.
  3. Final Answer:

    axes { axis { name 'os'; values 'linux', 'windows' } axis { name 'arch'; values 'x86', 'arm' } } -> Option D
  4. Quick Check:

    Correct axis syntax = axes { axis { name 'os'; values 'linux', 'windows' } axis { name 'arch'; values 'x86', 'arm' } } [OK]
Hint: Use axes { axis { name; values } } for matrix axes [OK]
Common Mistakes:
  • Using incorrect matrix or axis syntax
  • Mixing JSON-like syntax instead of Groovy
  • Missing semicolons or braces
3. Given this Jenkins matrix snippet:
axes {
  axis {
    name 'os'
    values 'linux', 'windows'
  }
  axis {
    name 'arch'
    values 'x86', 'arm'
  }
}
stages {
  stage('Build') {
    steps {
      echo "Building on ${os} for ${arch}"
    }
  }
}

How many total build combinations will Jenkins run?
medium
A. 6
B. 2
C. 4
D. 8

Solution

  1. Step 1: Count values in each axis

    Axis 'os' has 2 values: linux, windows. Axis 'arch' has 2 values: x86, arm.
  2. Step 2: Calculate total combinations

    Total combinations = 2 (os) * 2 (arch) = 4.
  3. Final Answer:

    4 -> Option C
  4. Quick Check:

    2 OS * 2 arch = 4 builds [OK]
Hint: Multiply axis values count for total combinations [OK]
Common Mistakes:
  • Adding instead of multiplying axis values
  • Counting only one axis
  • Misreading axis values count
4. You wrote this matrix build snippet but Jenkins fails with an error:
axes {
  axis {
    name 'os'
    values 'linux', 'windows'
  }
  axis {
    name 'arch'
    value 'x86', 'arm'
  }
}

What is the error and how to fix it?
medium
A. Typo: use 'values' instead of 'value' in second axis
B. Missing quotes around 'x86' and 'arm'
C. Axes block should be named 'matrix' not 'axes'
D. Use commas instead of spaces between values

Solution

  1. Step 1: Identify syntax error in axis definition

    The second axis uses 'value' instead of the correct 'values' keyword.
  2. Step 2: Correct the keyword

    Change 'value' to 'values' to fix the syntax error and allow multiple values.
  3. Final Answer:

    Typo: use 'values' instead of 'value' in second axis -> Option A
  4. Quick Check:

    Axis keyword must be 'values' [OK]
Hint: Check for 'values' keyword spelling in axes [OK]
Common Mistakes:
  • Using 'value' instead of 'values'
  • Forgetting commas between values
  • Misnaming axes block
5. You want to run a matrix build on OS (linux, windows) and arch (x86, arm), but only run the 'arm' builds on agents labeled 'arm-node'. How do you configure the matrix to achieve this?
hard
A. Set agent { label 'arm-node' } globally for all builds
B. Use agent { label "${arch == 'arm' ? 'arm-node' : ''}" } inside the matrix
C. Add when { expression { arch == 'arm' } } to skip arm builds
D. Use exclude { axis { name 'arch'; value 'arm' } } to remove arm builds

Solution

  1. Step 1: Understand agent labeling per axis value

    You want 'arm' builds to run only on 'arm-node' labeled agents, others on default.
  2. Step 2: Use conditional label assignment in agent block

    Using agent { label "${arch == 'arm' ? 'arm-node' : ''}" } assigns 'arm-node' label only for arm builds.
  3. Final Answer:

    Use agent { label "${arch == 'arm' ? 'arm-node' : ''}" } inside the matrix -> Option B
  4. Quick Check:

    Conditional agent label = Use agent { label "${arch == 'arm' ? 'arm-node' : ''}" } inside the matrix [OK]
Hint: Use conditional label in agent block for selective platforms [OK]
Common Mistakes:
  • Setting global agent label affecting all builds
  • Skipping arm builds instead of assigning correct agent
  • Excluding arm builds instead of targeting agent
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard