Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps Release Pipeline, Read Environment Variables from C# Code

Tags:

I thought the variables set in the Variables tab in a release pipeline were set as environment variables? On my TestCase Project I've got some settings stored as environment variables which are accessed during setup process of my tests, but in azure release pipeline it just comes back as null(this is using a hosted agent).

How can I access the Variables set in Variables tab of a release pipeline from my C# code?

My code to access Environment variables at the moment is

Environment.GetEnvironmentVariable("DevOpsUserName", EnvironmentVariableTarget.Machine)

This doesn't pull back the variables data.

like image 943
daeden Avatar asked Dec 10 '18 13:12

daeden


People also ask

How do I pass an environment variable to Azure pipeline?

Add the environment variable in the DevOps Pipeline In Azure DevOps, go to the “pipelines” and then go to the “library”. Add a variable group if there isn't one. And then add the variable “key/name” and the “value” to the variables section of the group and click on “save”.

How do you use variables in Azure DevOps release pipeline?

You define and manage these variables in the Variables tab in a release pipeline. In the Pipeline Variables page, open the Scope drop-down list and select "Release". By default, when you add a variable, it is set to Release scope. Share values across all of the tasks within one specific stage by using stage variables.

How do you access variables from variable group in Azure DevOps?

You can list the variables in a variable group with the az pipelines variable-group variable list command. If the Azure DevOps extension for CLI is new to you, see Get started with Azure DevOps CLI.


1 Answers

They are set as environment variables (excepting secret variables, which are not automatically converted to environment variables for security reasons).

However, they're not machine-level environment variables. They are process-level.

Use EnvironmentVariableTarget.Process.

like image 171
Daniel Mann Avatar answered Oct 12 '22 00:10

Daniel Mann