0
0
Jenkinsdevops~30 mins

Matrix builds for multi-platform in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Matrix builds for multi-platform
📖 Scenario: You are working in a software team that needs to build and test an application on multiple operating systems. To save time, you want Jenkins to run builds on Windows, Linux, and macOS automatically in parallel.
🎯 Goal: Create a Jenkins pipeline using a matrix build to run the same build steps on three platforms: windows, linux, and mac.
📋 What You'll Learn
Create a Jenkins pipeline with a matrix block
Define an axis called os with values windows, linux, and mac
Inside the matrix, run a simple shell or batch command to print the current OS
Print the build result for each platform
💡 Why This Matters
🌍 Real World
Matrix builds help teams test software on many platforms automatically, saving time and catching platform-specific bugs early.
💼 Career
Understanding matrix builds is important for DevOps engineers and build managers to optimize CI/CD pipelines for multi-platform projects.
Progress0 / 4 steps
1
Create the Jenkins pipeline skeleton
Write a Jenkins pipeline script starting with pipeline { and agent any to allow builds on any available agent.
Jenkins
Need a hint?

Start with pipeline { and specify agent any to run on any agent.

2
Add a matrix block with an axis for OS
Inside the pipeline, add a stages block with one stage named Build. Inside this stage, add a matrix block with an axis called os having values windows, linux, and mac.
Jenkins
Need a hint?

Use matrix { axes { axis { name 'os' values 'windows', 'linux', 'mac' } } inside the Build stage.

3
Add build steps inside the matrix to print the OS
Inside the matrix block, add a stages block with a stage named Run. Inside this stage, add a steps block that runs a shell command echo Building on ${os} for Linux and macOS, and a batch command echo Building on %os% for Windows. Use when condition to run the correct command based on the os value.
Jenkins
Need a hint?

Use script block with if (os == 'windows') to run bat command, else run sh command.

4
Print the build result for each platform
Add a post block inside the matrix block to print Build finished on ${os} after the build steps complete.
Jenkins
Need a hint?

Use post { always { echo "Build finished on ${os}" } } inside the matrix block.