iAutomate

Chendrayan Venkatesan

MVP | MCTS | MCP | ITIL

Publish Pester Test Results in GitLab CI

Pester | GitLab | PowerShell

Chendrayan Venkatesan

2-Minute Read

gitlab-series

Introduction

I wasn’t sure about the steps to publish the Pester test results in GitLab CI. So, I continued to search over the internet, and as you all know, the search teaches many things. I got many valuable tips and tricks, and here is my version that may help a few.

Requirement

  • Publish the Pester test results as shown below.
  • Consider using the PowerShell script analyzer in the pipeline.

Solution

.gitlab-ci.yml

stages:
  - pester

0-pester-test:
  stage: pester
  tags:
    - chen
  only:
    - main
  script:
    - | 
      $Container = New-PesterContainer -Path '.\tests\powershell.gitlab.tests.ps1' -Data @{
          Organization = ${url_prefix}; 
          PAT = ${gitlab_pat} 
      } 
      $Config = New-PesterConfiguration
      $Config.Run.PassThru = $true
      $Config.Run.Container = $Container
      $Result = Invoke-Pester -Configuration $Config 
      $Result | Export-JUnitReport -Path '.\testResults.xml'
  artifacts:
    paths: 
      - '.\testResults.xml'
    expire_in: 1 week
    reports:
      junit: .\testResults.xml

Test Case - For Demo (Pester with Param) - powershell.gitlab.tests.ps1

[CmdletBinding()]
param (
    $Organization,

    $PAT
)

Describe 'PowerShell.GitLab.Utility' {    
    BeforeAll {
        Import-Module .\powershell.gitlab.utility.psd1 -Verbose -Force
        Connect-GitLab -Organization $($Organization) -PAT $($PAT)
    }
    
    It "PowerShell Script Analyzer" {
        (Invoke-ScriptAnalyzer -Path .\tests -Recurse -Severity Error).Count | Should -BeExactly 0
    }

    It "Cmdlet Count" {
        (Get-Command -Module powershell.gitlab.utility).count  | Should -BeExactly 3
    }

    It "Get-GitLabProject" {
        Get-GitLabProject -GroupId '56890329' | Should -BeOfType [System.Management.Automation.PSCustomObject]
    }
}

Outcome

Outcome

PowerShell Script Analyzer (For Reference)

Outcome

Outcome

Summary

This blog post is just a start-over. I got a plan to release weekly blogs on GitLab to develop, test, and release PowerShell modules. Stay tuned!

Say Something

Comments

Nothing yet.

Recent Posts

Categories

About

Dedicated IT professional with a history of meeting company goals utilizing consistent and organized practices, skilled in working under pressure....