A PowerShell script to validate the YAML files of an Azure DevOps pipeline.
The script can be used to validate a whole hierarchy of pipeline YAML. It can be used on a local git working tree of an Azure DevOps repo which contains the YAML source of an existing pipeline.
To achieve this the script automates the following actions.
- Save your local changes (git stash).
- Create a temporary branch and check it out.
- Commit your stashed changes to the temporary branch.
- Push the temporary branch to the origin.
- Call the Azure DevOps API to validate the pipeline with the given pipeline ID and the temporary branch
- Display the validation result.
- Switch back to your original branch.
- Restore your local changes (index and working tree from git stash).
- Delete the temporary branch.
- In Azure DevOps UI create a PAT token in Azure DevOps that has the permission to execute and read your existing pipeline in your project.
- Create the environment variable
ValidateYamlPipeline_PAT
containing the PAT token. - Get the organisation, project name and pipeline ID from the Azure DevOps UI.
- Make YAML changes in your local git working tree.
- Run the script to validate your changes.
.\Validate-YamlPipeline.ps1 -OrgName "myorganisation" -ProjectName "MyProject" -PipelineId "2342"
Steps 1 to 3 only have to be done once while 4 and 5 would normally occur repeatedly during YAML pipeline development.
- PowerShell 7
- Azure DevOps account
- Azure DevOps git repo with YAML pipeline source
- Azure DevOps pipeline with ID
- Azure DevOps PAT token