Introduction
Two files are in this folder:
- Run-Pester.ps1. Executes a Pester test file and stores the results as Azure DevOps Test results. The methode is used in an Azure Powershell release task.
- task: AzurePowerShell@3
displayName: 'Run Tests'
inputs:
azureSubscription: 'sogeti-core-cloudboostsite-p'
ScriptPath: '_pipelines/VSTS/PowerShellScripts/PesterTest/Run-Pester.ps1'
ScriptArguments: '-ResourceGroupName "cloudboost-core-library-t" -TestFilePath "$(System.DefaultWorkingDirectory)\_pipelines\VSTS\PowerShellScripts\PesterTest\*.Tests.ps1" -SrcDirectory "$(System.DefaultWorkingDirectory)\_azure\ARM\$(folder)\" -OutputDirectory "$(Common.TestResultsDirectory)" -Username "$(ServicePrincipalUsername)" -Password "$(ServicePrincipalPassword)" -TenantId "$(TenantId)" -SubscriptionId "$(SubscriptionId)"'
FailOnStandardError: true
azurePowerShellVersion: LatestVersion
- GenericARM.Test.ps1. A files with tests whoch should work for all ARM deployments. The tests are:
- No error during deployment.
- …
Example
_azure/.vsts-ci.yml has the examples which validates all templates in the _azure directory.
first task installs Pester in the build server than two pairs of the same test tasks. The first executes and publishes the generic Pester Test the second the specific Pester Test for that ARM template.
- powershell: |
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Install-Module -Name Pester -Force -Scope CurrentUser -SkipPublisherCheck
displayName: 'Install Pester'
- task: AzurePowerShell@3
displayName: 'Run Tests'
inputs:
azureSubscription: 'sogeti-core-cloudboostsite-p'
ScriptPath: '_pipelines/VSTS/PowerShellScripts/PesterTest/Run-Pester.ps1'
ScriptArguments: '-ResourceGroupName "cloudboost-core-library-t" -TestFilePath "$(System.DefaultWorkingDirectory)\_pipelines\VSTS\PowerShellScripts\PesterTest\*.Tests.ps1" -SrcDirectory "$(System.DefaultWorkingDirectory)\_azure\ARM\$(folder)\" -OutputDirectory "$(Common.TestResultsDirectory)" -Username "$(ServicePrincipalUsername)" -Password "$(ServicePrincipalPassword)" -TenantId "$(TenantId)" -SubscriptionId "$(SubscriptionId)"'
FailOnStandardError: true
azurePowerShellVersion: LatestVersion
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: NUnit
testResultsFiles: '**\TEST-*.xml'
searchFolder: '$(Common.TestResultsDirectory)'
mergeTestResults: false
testRunTitle: 'Test Results for ARM Templates'
- task: AzurePowerShell@3
displayName: 'Run Tests'
inputs:
azureSubscription: 'sogeti-core-cloudboostsite-p'
ScriptPath: '_pipelines/VSTS/PowerShellScripts/PesterTest/Run-Pester.ps1'
ScriptArguments: '-ResourceGroupName "cloudboost-core-library-t" -TestFilePath "$(System.DefaultWorkingDirectory)\_azure\ARM\$(folder)\*.Tests.ps1" -SrcDirectory "$(System.DefaultWorkingDirectory)\_azure\ARM\$(folder)\" -OutputDirectory "$(Common.TestResultsDirectory)" -Username "$(ServicePrincipalUsername)" -Password "$(ServicePrincipalPassword)" -TenantId "$(TenantId)" -SubscriptionId "$(SubscriptionId)"'
FailOnStandardError: true
azurePowerShellVersion: LatestVersion
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: NUnit
testResultsFiles: '**\TEST-*.xml'
searchFolder: '$(Common.TestResultsDirectory)'
mergeTestResults: false
testRunTitle: 'Test Results for ARM Templates $(folder)'
Test results are collected during the Build.
