0
votes

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.

Command
Invoke-Pester -Script Get-Planet.Tests.ps1 -OutputFile Test-Pester.XML -OutputFormat NUnitXML

enter image description here

enter image description here

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

2
Can you please check the option 'Enable system diagnostics', and then check the full logs about your powershell task? Please make sure your powershell task has created the 'TestPester.XML' file successfully and check where the file is.Yujun Ding-MSFT
@ShubhiSharma no the publish test task, the powershell task.Shayki Abramczyk
@ShaykiAbramczyk doneShubhie267
@YujunDing-MSFT - I think it's not creating the file itselfShubhie267
@YujunDing-MSFT - pasted detailed logs of powershell do checkShubhie267

2 Answers

0
votes

Have you tried the following..

  1. Add '' around your path to the first pester command output, sounds odd but worth a try

  2. Add a test-path command using the path '$(System.DefaultWorkingDirectory)\TestPester.XML' before your publish task to make sure the file is being created

I find most of the time that the file has not been created or it can't properly resolve the path.

0
votes

I added Get-Planet.Tests.ps1 my test file instead of PowerShell file. That is why I was getting error.

I changed it to :

- task: PowerShell@2
    inputs:
    targetType: 'inline'
    script: |
      Install-Module -Name Pester -Force
  
  
      Invoke-Pester -CodeCoverage $(System.DefaultWorkingDirectory)\Get-Planet.psm1 `
                -CodeCoverageOutputFile $(System.DefaultWorkingDirectory)\Pester-Coverage.xml `
                -CodeCoverageOutputFileFormat JaCoCo `
                -OutputFile $(System.DefaultWorkingDirectory)\test-results.xml `
                -OutputFormat NUnitXml