PowerShell Module For JSON Schema Validation

Background Few days ago, I needed to validate JSON files against a predefined schema in a build pipeline in Azure DevOps. The validation needed to be performed using the Pester framework, and fail the build if the validation failed. In the past, I’ve always used this script (https://gist.github.com/JamesNK/7e6d026c8b78c049bb1e1b6fb0ed85cf) from James Newton-King, which leverages the JSON.Net libraries he developed. However, this time, I couldn’t it the script working on my Windows 10 laptop. I tried different versions of the DLLs, some won’t load, and the version that loads fine on my laptop threw some errors about System.Runtime library not referenced in

Continue reading

Pester Test Your ARM Template in Azure DevOps CI Pipelines

Introduction It is fair to say, I have spent a lot of time on Pester lately. I just finished up a 12 months engagement with a financial institute here in Melbourne. During this engagement, everyone in the project team had to write tests for any patterns / pipelines they are developing. I once even wrote a standalone pipeline only to perform Pester tests. One of the scenario we had to cater for is: How can you ensure the ARM template you are deploying only deploys the resources that you intended to deploy? In another word, if someone has gone rogue

Continue reading

PowerShell Module: PSPesterTest

Few weeks ago, the customer I was working for has a requirement that all the PowerShell scripts and in-house written modules must be validated against PSScriptAnalyzer as part of the build pipelines before it is implemented to their Azure environments in release pipelines. The validation must be performed using Pester so the test results can be easily consumed in the VSTS projects (i.e. dashboards). Luckily, I found this blog post: https://blog.kilasuit.org/2016/03/29/invoking-psscriptanalyzer-in-pester-tests-for-each-rule/, so I used this post as the starting point, and created a PowerShell module that performs pester test by invoking PS Script Analyzer rules. I named this module PSPesterTest.

Continue reading
%d bloggers like this: