Challenge - 5 Problems
Matrix Build Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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}"
}
}
}
}
}
}
}Attempts:
2 left
💡 Hint
Think about how matrix axes create parallel builds for each value.
✗ Incorrect
The matrix axis 'PLATFORM' has two values: 'linux' and 'windows'. Jenkins runs the inner stages once for each value, so the echo step runs twice, printing both platforms.
❓ Configuration
intermediate2: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'?
Attempts:
2 left
💡 Hint
Jenkins pipeline uses Groovy syntax without equals or colons in this context.
✗ Incorrect
The correct syntax uses 'name' and 'values' as keywords without assignment operators. Options A, B, and D use invalid Groovy syntax for this block.
❓ Troubleshoot
advanced2: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?
Attempts:
2 left
💡 Hint
Remember that each stage needs an agent unless inherited from parent.
✗ Incorrect
The pipeline sets 'agent none' globally, so each stage must specify an agent. The 'Compile' stage inside the matrix does not specify any agent, causing the error.
🔀 Workflow
advanced3: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?Attempts:
2 left
💡 Hint
Environment variables can be set dynamically inside a script block.
✗ Incorrect
Only option A sets the environment variable conditionally inside a script block, so WIN_PATH is defined only for windows builds. Other options set WIN_PATH unconditionally or incorrectly.
✅ Best Practice
expert3: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?
Attempts:
2 left
💡 Hint
Think about controlling concurrency rather than removing coverage or running sequentially.
✗ Incorrect
The 'maxParallel' option limits how many matrix combinations run at the same time, balancing resource use and coverage. 'failFast' stops builds on failure but doesn't reduce concurrency. Removing axes reduces coverage. Running sequentially wastes time.