5

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!

Mike
  • 2,561
  • 7
  • 34
  • 56

2 Answers2

2

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.

Mike
  • 2,561
  • 7
  • 34
  • 56
  • Thanks for sharing your solution here, would you please accept your solution as the answer? So it would be helpful for other members who get the same issue to find the solution easily. – Hugh Lin Apr 27 '20 at 01:40
0

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!

Grand
  • 164
  • 6