maester icon indicating copy to clipboard operation
maester copied to clipboard

Error PAth

Open kuroboshi opened this issue 10 months ago • 17 comments

Hello, i create a Azure Pipeline with Client secret. I have request a free parallelism in Azure DevOps. After i got it, when i run the pipeline, i have this issue:

`Starting: Publish Maester Html Report

Task : Publish Pipeline Artifacts Description : Publish (upload) a file or directory as a named artifact for the current run Version : 1.199.0 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/publish-pipeline-artifact

Artifact name input: TestResults ##[error]Path does not exist: /home/vsts/work/1/s/test-results Finishing: Publish Maester Html Report `

kuroboshi avatar Apr 15 '24 21:04 kuroboshi

@kuroboshi this usually indicates that the pipeline failed to run the tests, did you follow this guide to ensure the service principal you are using has correct perms?

https://maester.dev/docs/monitoring/azure-devops

jusso-dev avatar Apr 30 '24 03:04 jusso-dev

Hello, I use Maester with client secret. I check my Microsoft Graph permissions's, he seems OK.

Use Workload identity federation is required ?

kuroboshi avatar May 01 '24 16:05 kuroboshi

No you can use with workload identity or client secret.

Please share a screenshot of the permissions you have applied to the service principal.

jusso-dev avatar May 01 '24 20:05 jusso-dev

When you talk about service principal, it's this : image

kuroboshi avatar May 03 '24 10:05 kuroboshi

Ok thanks that looks fine, do you have Test Plans enabled with licensing as such for test plans?

jusso-dev avatar May 03 '24 10:05 jusso-dev

I request a free parallelism in Azure Devops, watch my email below : image

kuroboshi avatar May 03 '24 14:05 kuroboshi

It's possible the path it's trying to publish to does in fact not exist

Artifact name input: TestResults
##[error]Path does not exist: /home/vsts/work/1/s/test-results

What is your folder structure in git for tests? Review the folder structure and ensure that the relative file path the test result publish step is attempting to publish to, is correct based on your git folder structure.

jusso-dev avatar May 03 '24 21:05 jusso-dev

I create manually the folders : image

In debug mode, i see the creation of folder : image

image

kuroboshi avatar May 05 '24 10:05 kuroboshi

Ah ha! so if you read that error message, this isn't an issue with the test path at all, as I first suspected your tests are failing to run.

The error message states the variable "userName" is missing. You need to define two variables as per the docs, CLIENTSECRET and CLIENTID, please check you have those set.

jusso-dev avatar May 05 '24 10:05 jusso-dev

I re-add the variables but in the first time i don't check "Keep this value secret", below the result with warning :

image

In the second run, i just check "Keep this value secret" and i have a error : image image

kuroboshi avatar May 05 '24 12:05 kuroboshi

Can you share your yaml? The yaml provided in the maester docs doesn't use a variabled called username but your error seems to indicate you are referring to a variable with that name

merill avatar May 06 '24 21:05 merill

Hello, here it is

`# Maester Daily Tests

trigger:
  - main

schedules:
  - cron: "0 0 * * *"
    displayName: Daily midnight build
    branches:
      include:
        - main

pool:
  vmImage: ubuntu-latest

steps:
  - pwsh: |
      # Connect to Microsoft Graph
      $clientSecret = ConvertTo-SecureString -AsPlainText $env:PS_ClientSecret -Force
      [pscredential]$clientSecretCredential = New-Object System.Management.Automation.PSCredential($env:CLIENTID, $clientSecret)
      Connect-MgGraph -TenantId $env:TENANTID -ClientSecretCredential $clientSecretCredential

      # Install Maester
      Install-Module Maester -Force

      # Configure test results
      $PesterConfiguration = New-PesterConfiguration
      $PesterConfiguration.TestResult.Enabled = $true
      $PesterConfiguration.TestResult.OutputPath = '$(System.DefaultWorkingDirectory)/test-results/test-results.xml'

      # Run Maester tests
      Invoke-Maester -Path $(System.DefaultWorkingDirectory)/tests/Maester/ -PesterConfiguration $PesterConfiguration -OutputFolder '$(System.DefaultWorkingDirectory)/test-results'
    env:
      PS_ClientSecret: $(CLIENTSECRET)
    continueOnError: true
    displayName: Run Maester Tests
  - publish: $(System.DefaultWorkingDirectory)/test-results
    artifact: TestResults
    displayName: Publish Maester Html Report
  - task: PublishTestResults@2
    inputs:
      testResultsFormat: "NUnit"
      testResultsFiles: "**/test-results.xml"
    displayName: Publish Pester Test Results`

kuroboshi avatar May 07 '24 09:05 kuroboshi

So this yaml looks okay.

Can you confirm that you have a variable named CLIENTID defined in the Variables page?

The most likely cause of the error is the client id is not being passed through. You can try adding a Write-Host $env:CLIENTID to verify if the id is being passed into PowerShell.

merill avatar May 08 '24 10:05 merill

Hello,

The problem doesnt appair when the variables is not hidden : image

I'm not sure, but when I check the "Keep this value secret" box, I must be missing something for the mapping. image

kuroboshi avatar May 09 '24 20:05 kuroboshi

For your information i doesnt see the client id with "Write-Host $env:CLIENTID" when i check the "Keep this value secret"

Otherwise I have the report but I still have an error : image

kuroboshi avatar May 09 '24 20:05 kuroboshi

if your using secret vars you will need to change the pwsh task to the full task and set the secret pipeline variable as a environment variable in the script

 - task: PowerShell@2
          env: 
            SECRETVALUE: $(SECRETVARNAMEHERE)
          inputs:
            targetType: inline
            script: |
                {Your pwsh script here}

You can then use env vars as usual to access the secret variable. Sorry if my example isnt the best it is late!

Please see Set secret variables for reference

DrPye avatar May 11 '24 01:05 DrPye

@kuroboshi Did you manage to get to the bottom of this?

DrPye avatar May 16 '24 00:05 DrPye

Hello, sorry i was in holidays. @DrPye My pwsh script is :

Invoke-Maester -Path $(System.DefaultWorkingDirectory)/tests/Maester/ -PesterConfiguration $PesterConfiguration -OutputFolder '$(System.DefaultWorkingDirectory)/test-results'

kuroboshi avatar Jun 01 '24 17:06 kuroboshi

@kuroboshi only the ClientSecret needs to have the secret hidden. So what you have done above is correct and has fixed the issue.

merill avatar Jun 02 '24 08:06 merill

Closing inactive thread.

merill avatar Jun 22 '24 13:06 merill