Error when Octopus tries to run PowerShell script

I have a process step to run a powershell script that initiates some Selenium Webdriver tests.
The script is as follows:

set nunitPath "C:\AutomatedTests"
cd $nunitpath
nunit-console SiteCore.nunit /include:BulkyWasteTests

When the release process tries to run the script, it results in the following error:

Set-Location : Cannot find path ‘C:\AutomatedTests’ because it does not exist.
At C:\Octopus\Work\20170116081615-13\Script.ps1:2 char:3

  • cd <<<< $nunitpath

    • CategoryInfo : ObjectNotFound: (C:\AutomatedTests:String) [Set-

    Location], ItemNotFoundException

    • FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

The remote script failed with exit code 1

The location where the tests are is correct so I don’t understand what may be wrong. Any help would be appreciated.
Thanks.

Hi,

Thanks for reaching out.

Can you change your script for this and try again?

$nunitpath = "C:\AutomatedTests" 

If(Test-path $nunitpath){
    cd $nunitpath 
    nunit-console SiteCore.nunit /include:BulkyWasteTests
}
else{
    throw "Path [$nunitpath] not found on $($env:computername)"
}

Regards,
Dalmiro

Hello Dalmiro - thank you for your suggestion. I changed the script and now the error returned is:

Path [C:\AutomatedTests] not found on MYEACCTESTV01

At C:\Octopus\Work\20170117075256-15\Script.ps1:8 char:10

  • throw <<<<  "Path [$nunitpath] not found on $($env:computername)"
    
    • CategoryInfo : OperationStopped: (Path [C:\Automa…n MYEACCTES
      TV01:String) [], RuntimeException
    • FullyQualifiedErrorId : Path [C:\AutomatedTests] not found on MYEACCTEST
      V01

The remote script failed with exit code 1

Regards,
Michael

Hi MIchael,

The script I gave you seems to confirm the fact that c:\AutomatedTests doesn’t exist on the machine MYEACCTESTV01, which is the same message you were getting with the initial script.

  • Are you creating that folder on MYEACCTESTV01 during the deployment, or was it manually created beforehand?

  • Are you deploying content to c:\AutomatedTests during the deployment, which you plan to use in that script that is failing?

Regards,
Dalmiro

Hi Dalmiro
Thank you for your reply. It was a colleague who manually set up this location for me. This where the bin folder from the Visual Studio solution containing the NUnite files and tests has been copied. This location and folder already exists and is not being created as part of the deployment process.
Perhaps it is a permissions problem? I will ask my colleague to investigate.
Regards,
Michael

Hi Dalmiro
We have now created a new location and the location error is no longer generated so we can rule that out, however, there is now another error:

The term ‘nunit-console’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Octopus\Work\20170118115419-31\Script.ps1:5 char:52

  • set-executionpolicy Unrestricted; nunit-console <<<<  SiteCore.nunit /incError
    

lude:BulkyWasteTests
+ CategoryInfo : ObjectNotFound: (nunit-console:String) [], Paren
tContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException

The remote script failed with exit code 1

To test the powershell script syntax, I copied it from the process step and created a ps1 file. I am able to run this file manually and it successfully initiates the nunit-console so I assume the syntax in the process step is correct.
I also tried adding set-executionpolicy Unrestricted; but it did not make any difference.
Thanks again,
Michael

Hi Michael,

Keep in mind that during the deployment, the script gets executed by the account running the Tentacle service on that VM and not by your own account (unless you speficifically set the Tentacle to run under your own account). If the account running the Tentacle is going to be running Nunit-console from the path assigned to $nunitpath, you need to make sure to do either of the following:

Hope that helps.

Dalmiro

Hi Dalmiro
I have both Nunit-console on the PATH environment variable, and the nunit-console.exe in the correct location but still I get:

The term ‘nunit-console’ is not recognized as the name of a cmdlet, function, script file, or operable program.
ObjectNotFound: (nunit-console:String) [], ParentContainsErrorRecordException

  • FullyQualifiedErrorId : CommandNotFoundException

Thanks
Michael

Hi again Dalmiro
Some further information, i changed the Octopus service to run under the local system account and the deployment process now sees the nunit-console, however, there is now one more problem but it is nothing to do with Octopus or the Powershell script.

The error is: : SiteCore.BulkyWasteTests.BulkyWasteTests
SetUp : OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:65356/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.

According to what I have found on Google, this appears to be a .Net binding problem.

Thanks for all your help.
Michael

Hi Michael,

The fact that it worked for Local System Account makes me think the term is not recognized error is still related to the availability of the path in the Environment Variable. Glad to hear you found a workaround for it.

Yeah that other error doesn’t seem related to Octopus at all. More like related to the Selenium drivers, but don’t take my word on that one :).

Good luck with that new error. Hope you find a solution for it soon (or already!).

Cheers,
Dalmiro