daeden
daeden

Reputation: 176

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

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.

Upvotes: 7

Views: 3575

Answers (2)

Mygeen
Mygeen

Reputation: 161

You can use Environment.GetEnvironmentVariable("DevOpsUserName", EnvironmentVariableTarget.Process), as Daniel mentioned.

Or you can directly use Environment.GetEnvironmentVariable("DevOpsUserName"), which is equivalent to the previous statement and targets the process-level environment variables.

Upvotes: 2

Daniel Mann
Daniel Mann

Reputation: 59016

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.

Upvotes: 4

Related Questions