C
C#2w ago
kmanjt

Azure DevOps Pipelines: Environment Variables Not Available in dotnet test Command

I'm using Azure DevOps and have an AzureCLI task set up to run integration tests with the dotnet test command. I'm encountering an issue where environment variables set in the task do not seem to be available when dotnet test is executed. Here is the relevant part of my pipeline configuration:
- task: AzureCLI@2
displayName: 'Run Integration Tests Inside AZ CLI'
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: pscore
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
# Commands to set environment variables
Write-Host "##vso[task.setvariable variable=TENANT_ID;issecret=true]$(tenantId)"
...

$env:TENANT_ID = "$(tenantId)"
...

# Running dotnet test
dotnet test --configuration $(buildConfiguration) ...
- task: AzureCLI@2
displayName: 'Run Integration Tests Inside AZ CLI'
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: pscore
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
# Commands to set environment variables
Write-Host "##vso[task.setvariable variable=TENANT_ID;issecret=true]$(tenantId)"
...

$env:TENANT_ID = "$(tenantId)"
...

# Running dotnet test
dotnet test --configuration $(buildConfiguration) ...
The variables like TENANT_ID are set using ##vso[task.setvariable] and also attempted to be set in the script's session scope using $env: for use in the same script. However, these variables do not seem to be accessible or correctly passed to the dotnet test command. What could be causing this issue, and how can I ensure that these environment variables are correctly passed to and accessible by the dotnet test command within the same Azure CLI task?
2 Replies
kmanjt
kmanjt2w ago
Please note, I require the dotnet test to be inside of the AzureCLI@2 task, to make use of the new AzurePipelinesCredential from the Azure Identity SDK
p.armytank
p.armytank2w ago
are you sure you're passing in tenantId correctly? maybe try printing it out in the script.