2
votes

I have a standard .NET Core (Ubuntu) pipeline on Azure Devops and within my Test project, I use environment variables. Within my pipeline, I have defined my group variables like so

variables:
- group: MyApiVariables

Whenever I run the tests for my project

- task: DotNetCoreCLI@2
  displayName: "Testing Application"
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

The actual environment variables aren't passed in. They are blank.

What am I missing to get this running? I've even defined variables in the edit pipeline page too with no luck

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo $AppConfigEndpoint
  env:
    AppConfigEndpoint: $(AppConfigEndpoint)
    ApiConfigSection: $(ApiConfigSection)

Thanks!

2

2 Answers

1
votes

CASING Strikes again! MyVariableName was turned into MYVARIABLENAME on Azure Devops. I changed my variable names in my group to all caps and it worked. I spent way too much time on this.

0
votes

Mike, I see that you use variable groups. I assume it may cause your issue. Take a look at variable passing example I made:

First I had to create new variable group in Library:

enter image description here

Here is a pipeline code that reference created variables:

# Set variables group reference
variables:
- group: SampleVariableGroup

steps:
  - powershell: 'Write-Host "Config variable=$(configuration) Platform variable=$(platform)"'
    displayName: 'Display Sample Variable'  

I used PowerShell task to verify if variables were properly passed to the job.

enter image description here

As you can see both configuration & platform values were displayed correctly.

In fact you can't go wrong that way, unless you start to mix variable groups with variables defined in a yaml. In such scenario you'll have to use name/value syntax for the individual (non-grouped) variables.

Please see Microsoft Variable Groups documentation. Such example is well explained there. I also suggest to take closer look at general Variables Documentation.

In case of referencing variables in other tasks here is a great example from MS (it should work everywhere in same manner):

# Set variables once
variables:
  configuration: debug
  platform: x64

steps:

# Use them once
- task: MSBuild@1
  inputs:
    solution: solution1.sln
    configuration: $(configuration) # Use the variable
    platform: $(platform)

# Use them again
- task: MSBuild@1
  inputs:
    solution: solution2.sln
    configuration: $(configuration) # Use the variable
    platform: $(platform)

Good luck!