Atlassian Bamboo PowerShell Pester Integration

Some time ago I have moved one of my PowerShell projects to a new Atlassian Bitbucket server with Bamboo connection for Continuous Integration and Continuous Deployment. To continue using my existing code validation scripts I was looking for a Bamboo PowerShell Pester Integration. For the interoperability both tools, Pester and Bamboo, can handle Test-Results in NUnit XML format.

My example plan is configured with default Bamboo settings and some additional variables which are used for the detailed integration tests of the project (not covered by this blog post).

Bamboo PowerShell Pester Integration - Variables

Stage Jobs

A Bamboo plan has beside the basic configuration one or more stages. The stages within
a plan can have one or more jobs. Bamboo executes the plans of a stage in parallel.

Bamboo PowerShell Pester Integration - Stages and Jobs

On the other hand, jobs can have one or more tasks, which are executed one after the other. A task is a piece of work that is being executed as part of the build. 

Source Code Checkout

The source code checkout is a default task. This step is required so that the agent can execute the following tasks.

Bamboo PowerShell Pester Integration - Source Code Checkout

Import Module PowerShell task

This task imports the Pester PowerShell Module into the PowerShell Session of the Bamboo Agent. In most cases, this is not necessary because of PowerShell autoload.

Import-Module Pester -force
Bamboo PowerShell Pester Integration - PowerShell task

Pester PowerShell task

That’s the most important task, it runs the Pester tests. The results are returned as NUnitXml.

$pester_xml = "./pester1_xml.xml"
$result = Invoke-Pester -Script ".\tests\Basic.test.ps1" -OutputFile $pester_xml -OutputFormat NUnitXml

if ($result.FailedCount -gt 0) {
    Write-Error "$($result.FailedCount) tests did not pass!"
}
Bamboo PowerShell Pester Integration - Pester PowerShell task

NUnit Parser configuration

This task parses the Pester test results from the previous tasks NUnitXml result file.

Bamboo PowerShell Pester Integration - NUnit Parser

Job Results

Thanks to the tight Bamboo PowerShell Pester integration all test results are well presented in the web interface.

Bamboo PowerShell Pester Integration - Job results

If one of the tests throws an error, the details are collected from the task and are also presented in the web interface.

Bamboo PowerShell Pester Integration - Job error results

Share with:

Leave a Reply