Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error PAth #102

Closed
kuroboshi opened this issue Apr 15, 2024 · 20 comments
Closed

Error PAth #102

kuroboshi opened this issue Apr 15, 2024 · 20 comments

Comments

@kuroboshi
Copy link

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
`

@jusso-dev
Copy link

@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

@kuroboshi
Copy link
Author

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

Use Workload identity federation is required ?

@jusso-dev
Copy link

No you can use with workload identity or client secret.

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

@kuroboshi
Copy link
Author

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

@jusso-dev
Copy link

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

@kuroboshi
Copy link
Author

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

@jusso-dev
Copy link

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.

@kuroboshi
Copy link
Author

I create manually the folders :
image

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

image

@jusso-dev
Copy link

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.

@kuroboshi
Copy link
Author

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

@merill
Copy link
Contributor

merill commented May 6, 2024

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

@kuroboshi
Copy link
Author

kuroboshi commented May 7, 2024

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`

@merill
Copy link
Contributor

merill commented May 8, 2024

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.

@kuroboshi
Copy link
Author

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
Copy link
Author

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

@DrPye
Copy link
Contributor

DrPye commented May 11, 2024

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
Copy link
Contributor

DrPye commented May 16, 2024

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

@kuroboshi
Copy link
Author

kuroboshi commented Jun 1, 2024

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'

@merill
Copy link
Contributor

merill commented Jun 2, 2024

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

@merill
Copy link
Contributor

merill commented Jun 22, 2024

Closing inactive thread.

@merill merill closed this as completed Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants