My pipeline build is successful but I needed to publish the results in .xml file which is happening locally but not in DevOps - It says TestPester file not found.
When I use these commands locally - all tests are passed and it creates TestPester file automatically.
CommandInvoke-Pester -Script Get-Planet.Tests.ps1 -OutputFile Test-Pester.XML -OutputFormat NUnitXML
The pipeline code :
trigger:
- main
pool:
vmImage: windows-latest
steps:
- task: PowerShell@2
inputs:
filePath: 'Get-Planet.Tests.ps1'
workingDirectory: '$(System.DefaultWorkingDirectory)'
script: |
Install-Module -Name Pester -Force -SkipPublisherCheck
Import-Module Pester
Invoke-Pester -Script $(System.DefaultWorkingDirectory)\Get-Planet.Tests.ps1 -OutputFile $(System.DefaultWorkingDirectory)\TestPester.XML -OutputFormat NUnitXML
Invoke-Pester -CodeCoverage '$(System.DefaultWorkingDirectory)\Get-Planet.Tests.ps1' -CodeCoverageOutputFile '$(System.DefaultWorkingDirectory)\Pester-Coverage.xml' -CodeCoverageOutputFileFormat JaCoCo
- task: PublishTestResults@2
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '$(System.DefaultWorkingDirectory)\TestPester.XML'
mergeTestResults: true
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '**/Pester-Coverage.xml'
pathToSources: '$(System.DefaultWorkingDirectory)'
LOG FILE
2021-04-07T09:15:46.0910514Z ##[section]Starting: PublishTestResults
2021-04-07T09:15:46.1265107Z ==============================================================================
2021-04-07T09:15:46.1265611Z Task : Publish Test Results
2021-04-07T09:15:46.1265893Z Description : Publish test results to Azure Pipelines
2021-04-07T09:15:46.1266118Z Version : 2.180.0
2021-04-07T09:15:46.1266332Z Author : Microsoft Corporation
2021-04-07T09:15:46.1266847Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
2021-04-07T09:15:46.1267241Z ==============================================================================
2021-04-07T09:15:47.1966443Z [command]"C:\Program Files\dotnet\dotnet.exe" --version
2021-04-07T09:15:48.7472296Z 5.0.201
2021-04-07T09:15:48.7517977Z ##[warning]No test result files matching D:\a\1\s\TestPester.XML were found.
2021-04-07T09:15:48.8193796Z ##[section]Finishing: PublishTestResults
Powershell logs :
Generating script. Formatted command: . 'D:\a\1\s\Get-Planet.Tests.ps1' ========================== Starting Command Output =========================== "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a_temp\3dee7bed-1e4b-4a16-8e09-674f5ac01d78.ps1'"
Starting discovery in 1 files. Discovery finished in 1.06s. [+] D:\a\1\s\Get-Planet.Tests.ps1 5.22s (1.21s|3.05s) Tests completed in 5.36s Tests Passed: 6, Failed: 0, Skipped: 0 NotRun: 0 Finishing: PowerShell