0

I have a Windows 10 box where I'm running my own Azure Build Agent that I've installed

I set some environment variables on said box, using setx commands, like this: screenshot of cmd.exe

I then rebooted the whole box to ensure whatever process I am launching (visual studio, or build agent) has a proper opportunity to read the environment

Running the code locally in Visual Studio works, and I can write the contents of the vars with a simple Console.WriteLine within my UnitTest, e.g.:

    private static string _user;
    private static string _pass;

    [ClassInitialize]
    public static void ClassInit(TestContext ctx)
    {
        IConfiguration config = new ConfigurationBuilder()
            .AddEnvironmentVariables()
            .Build();

        _user = config["OrderEntryClient:UnitTestCredentials:UserName"];
        _pass = config["OrderEntryClient:UnitTestCredentials:Password"];

        Console.WriteLine($"Here are my vars:{_user}-{_pass}");
    }

Output: Here are my vars:UserName123-Password123456

I've seen some stuff on the interwebs about MSBuild being picky about environment variables, and maybe this is all by design when running multiple builds on the same machine simultaneously.. but.. what am I doing wrong?

The Console.WriteLine output on the build agent shows nothing has loaded when I run it

bkwdesign
  • 1,953
  • 2
  • 28
  • 50

1 Answers1

0

While many environment variables are reflected in dev.azure.com as 'Capabilities' it didn't seem to matter what I did, or how many times I restarted it, I could not make my new variables available

I eventually gave up and did the following:

Create a .env file under agent's root directory and put environment variables you want to set into the file as following format:

 MyEnv0=MyEnvValue0
 MyEnv1=MyEnvValue1
 MyEnv2=MyEnvValue2
 MyEnv3=MyEnvValue3
 MyEnv4=MyEnvValue4

Above was taken from here: learn.microsoft.com

bkwdesign
  • 1,953
  • 2
  • 28
  • 50