Azure-pipelines-tasks: Add environment variables to .NET Core task

Created on 2 Sep 2019  路  8Comments  路  Source: microsoft/azure-pipelines-tasks

Required Information

Question, Bug, or Feature?
Type: Feature

Enter Task Name: .NET Core

list here (V# not needed):
https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/DotNetCoreCLIV2

Issue Description

Currently if one needs to supply environment variable to the .NET Core task they need to use a script task. It is very common that the dotnet test command needs environment variables to better configure the test. The current way to provide environment variable is not good enough, as it capitalizes every variable, and that makes it impossible to use that as configuration that is not uppercase for a .NET Core service (using .NET Core configuration).

The way to fix this is to simply allow for environment variables to be specified, as it is currently possible on the script task.

If you need more information please let me know.

Release enhancement

Most helpful comment

This works:

yaml - task: DotNetCoreCLI@2 inputs: command: test projects: "tests/**/*Tests.csproj" env: foo: 1 bar: 2

All 8 comments

You can create a powershell inline script and define the variable as:
$env:variable = "value1"

@internetgdl Not on the azure-pipelines.yaml DotNetCoreCLIV2 task, you can't. This variable on a previous script would not survive for the next task.

I stumbled over the same problem. Finally I found out that environment variables can be assigned to any task. See the pseudo schema for the tasks here: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#task
@giggio , this means simply add env: with the desired vars on the same indent as the task.

Is this new? Ok, this solves my problem.

Not sure, when this came in, I am pretty new to this ;-). Happy to hear that it solves your problem :-).

I stumbled over the same problem. Finally I found out that environment variables can be assigned to any task. See the pseudo schema for the tasks here: https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#task
@giggio , this means simply add env: with the desired vars on the same indent as the task.

Is there a way to do this for classic pipelines?

Could you share the exact Yaml syntax?

Doesn't like mine...

- task: DotNetCoreCLI@2 enabled: true displayName: 'Run GremlinApp' inputs: command: 'run' projects: './GremlinApp/GremlinApp.csproj' workingDirectory: './GremlinApp' env: AUTHKEY KEY

This works:

yaml - task: DotNetCoreCLI@2 inputs: command: test projects: "tests/**/*Tests.csproj" env: foo: 1 bar: 2

Was this page helpful?
0 / 5 - 0 ratings