5
votes

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.

2

2 Answers

3
votes

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.

1
votes

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.