Why would installing Azure SDK 2.1 or powershell 3 on the build server break some of our tests which run in powershell?

StackOverflow https://stackoverflow.com/questions/18637256

Question

we have some tests which execute a powershell script on some files to ensure that the script processes the files correctly.

This is an example:

    [TestMethod]
    [DeploymentItem(@"BuildScripts\CheckForFxCop.ps1")]
    [DeploymentItem(@"TestData\TestWithIncorrectFxCop\TestWithIncorrectFxCop.csprojext", "TestWithIncorrectFxCop")]
    public void WhenFxCopHasWrongValueFails()
    {
        string projectFileToTest = Path.Combine(Directory.GetCurrentDirectory(), "TestWithIncorrectFxCop", "TestWithIncorrectFxCop.csprojext");
        string scriptFileToExecute = Path.Combine(Directory.GetCurrentDirectory(), "CheckForFxCop.ps1");
        ProcessStartInfo startInfo = new ProcessStartInfo
        {
            FileName = "powershell.exe",
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = false
        };
        startInfo.Arguments = string.Format(@"& '{0}' '{1}' csprojext", scriptFileToExecute, projectFileToTest);

        var process = new Process { StartInfo = startInfo };
        process.Start();

        ... assert some stuff...
    }

These tests have been running for the last 9 months on the build server.

We installed powershell 3 on one server recently and this made all of these tests fail with:

System.ComponentModel.Win32Exception: The system cannot find the file specified

thrown at the process.Start() line.

We stopped tests running on this server temporarily and just used the servers which don't have powershell 3.0 installed.

We have recently installed AzureSDK 2.1 on the other build servers and we are now getting the same issue on all the servers.

If we log on to the build machine as the build agent user and manually start powershell and run the commands that the test is running it seems to succeed ok.

Does anyone have any idea what might be causing these tests to fail now? Or have any ideas about how we might be able to diagnose the issue?

Was it helpful?

Solution 2

So it looks like the issue was related to

CreateNoWindow = false

we had some other tests which had this set to true that were succeeding and something about running them as the build agent account (or the fact that the build agent runs a s a service more likely) meant that they were failing, not sure why the file not found was the error though.

Anyway problem solved I think.

OTHER TIPS

Have you tried passing a fully qualified path to startInfo.FileName instead of just Powershell.exe incase there's a problem with %PATH% since the update

Complete total guess, but any chance your running into FileSystemRedirector 32 vs. 64 issues as seen in this answer - Process.Start(): The system cannot find the file specified, but my file path seems to be legit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top