我在Octopus Deploy中有一个流程步骤,通过调用PowerShell脚本来运行一些Selenium WebDriver测试,但它导致了错误。
PowerShell 脚本如下所示:
set nunitPath="C:AutomatedTests"
cd %nunitPath%
nunit-console SiteCore.nunit /include:BulkyWasteTests
进行部署并执行运行脚本的流程步骤时,将发生以下错误:
Set-Location : Cannot find path 'C:OctopusWork20170110115049-7%nunitPath%' because it does not exist.
At C:OctopusWork20170110115049-7Script.ps1:2 char:3
+ cd %nunitPath%
+ CategoryInfo : ObjectNotFound: (C:OctopusWork...-7%nunitPath %:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
The remote script failed with exit code 1
我不明白为什么错误报告的位置与PowerShell脚本中指定的位置不同。任何帮助非常感谢。
cd 是 Set-Location 的别名,因此您可以通过查看错误来判断它是您需要更改的第二行。 您的 cd 行正在尝试将位置设置为 %nunitpath% 环境变量,而不是 nunitPath 脚本变量。
要引用脚本变量,请使用$nunitpath
因此,您的脚本应如下所示:
set nunitPath "C:AutomatedTests"
cd $nunitpath
nunit-console SiteCore.nunit /include:BulkyWasteTests
编辑了@4c74356b41条额外的正确注释。
PowerShell 不使用%variablename%
语法来扩展字符串中的环境变量引用。这是cmd.exe语法。在 PowerShell 中,改为编写$env:variablename
。