Create a multi-platform pipeline
Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020
This is a step-by-step guide to using Azure Pipelines to build on macOS, Linux, and Windows.
Prerequisites
Make sure you have the following items:
A GitHub account where you can create a repository. Create one for free.
An Azure DevOps organization. Create one for free. If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.
An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier.
Get the sample code
You can use Azure Pipelines to build an app on written in any language, on multiple platforms at the same time.
Go to https://github.com/Azure-Samples/js-e2e-express-server.
Fork the repo into your own GitHub account.
You should now have a sample app in your GitHub account.
Add a pipeline
In the sample repo, there's no pipeline yet. You're going to add jobs that run on three platforms.
Go to your fork of the sample code on GitHub.
Choose 'Create new file'. Name the file
azure-pipelines.yml
, and give it the contents below.
# Build NodeJS Express app using Azure Pipelines
# https://learn.microsoft.com/azure/devops/pipelines/ecosystems/javascript?view=azure-devops
strategy:
matrix:
linux:
imageName: 'ubuntu-latest'
mac:
imageName: 'macOS-latest'
windows:
imageName: 'windows-latest'
pool:
vmImage: $(imageName)
steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
- script: |
npm install
npm test
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/TEST-RESULTS.xml'
testRunTitle: 'Test results for JavaScript'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/coverage'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
- task: PublishBuildArtifacts@1
At the bottom of the GitHub editor, select Commit changes.
Each job in this example runs on a different VM image. By default, the jobs run at the same time in parallel.
Note: script
runs in each platform's native script interpreter: Bash on macOS and Linux, CMD on Windows.
See multi-platform scripts to learn more.
Create the pipeline
Now that you've configured your GitHub repo with a pipeline, you're ready to build it.
Sign in to your Azure DevOps organization and navigate to your project.
In your project, go to the Pipelines page, and then select New pipeline.
Select GitHub as the location of your source code.
For Repository, select Authorize and then Authorize with OAuth.
You might be redirected to GitHub to sign in. If this happens, then enter your GitHub credentials. After you're redirected back to Azure Pipelines, select the sample app repository.
For the Template, Azure Pipelines analyzes the code in your repository. If your repository already contains an
azure-pipelines.yml
file (as in this case), then this step is skipped. Otherwise, Azure Pipelines recommends a starter template based on the code in your repository.Azure Pipelines shows you the YAML file that it will use to create your pipeline.
Select Save and run, and then select the option to Commit directly to the main branch.
The YAML file is pushed to your GitHub repository, and a new build is automatically started. Wait for the build to finish.
FAQ
Can I build my multi-platform pipeline on both self-hosted and Microsoft-hosted agents?
You can, you would need to specify both a vmImage
and a Pool
variable, like the following example. For the hosted agent, specify Azure Pipelines
as the pool name, and for self-hosted agents, leave the vmImage
blank. The blank vmImage
for the self-hosted agent may result in some unusual entries in the logs but they won't affect the pipeline.
strategy:
matrix:
microsofthosted:
poolName: Azure Pipelines
vmImage: ubuntu-latest
selfhosted:
poolName: FabrikamPool
vmImage:
pool:
name: $(poolName)
vmImage: $(vmImage)
steps:
- checkout: none
- script: echo test
Next steps
You've just learned the basics of using multiple platforms with Azure Pipelines. From here, you can learn more about:
- Jobs
- Cross-platform scripting
- Templates to remove the duplication
- Building Node.js apps
- Building .NET Core, Go, Java, or Python apps
For details about building GitHub repositories, see Build GitHub repositories.
Feedback
Submit and view feedback for