简体   繁体   中英

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM