How To Run Pester Tests Using Azure Pipeline Builds With Test Results!
github repo: https://github.com/devopsdina/ado-pipelines-demo-win
I write a ton of PowerShell when helping teams develop DevOps goodies. I was super excited when Azure DevOps came out, especially for free!
Azure DevOps will actually supply free standard Microsoft hosted build agents which come in both Windows and Linux, more information about the free agents can be found here.
In our example we will use the Microsoft hosted vs2017-win2016 build agent.
The pipeline files are written in YAML. The schema for the pipeline files is defined here. You should have a high level understanding of the schema.
Essentially, in our build pipeline for our PowerShell scripts we need to run Pester (PowerShell’s unit testing framework) and publish the test results. In order to do this, we need to publish the Pester test results to an XML file with NUnit as the test runner for Azure DevOps tests to pick it up and show us a pretty visual of our test results.
Now you might be thinking why not just run invoke-pester in the
Since we have to publish the results to a file, I prefer having a dedicated script but one could also do this by running an inline PowerShell step. The
Invoke-PesterAzureDevOps.ps1 looks like this:
Hopefully, you are following…because that is all!!
Once you commit this
azure-pipelines.yml file on your branch it should automatically run (Azure DevOps will see the file and run it).
I will explicitly say, you must have some working pester tests but as long as you, bada-bing, bada-boom any newly added tests will automatically run now too.
All code referenced is available in github with a hello world script example and a few Pester tests available here.
Here are screenshots of what you can expect to see after you’ve pushed the pipelines file.