【问题标题】:Octopus Deploy not running PowerShell scriptOctopus Deploy 未运行 PowerShell 脚本
【发布时间】:2017-01-10 15:13:07
【问题描述】:

我在 Octopus Deploy 中有一个流程步骤,可以通过调用 PowerShell 脚本来运行一些 Selenium WebDriver 测试,但这会导致错误。

PowerShell脚本如下:

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

当部署发生并且运行脚本的 Process Step 发生时,会出现以下错误:

Set-Location : Cannot find path 'C:\Octopus\Work\20170110115049-7\%nunitPath%\' because it does not exist.

At C:\Octopus\Work\20170110115049-7\Script.ps1:2 char:3

+ cd %nunitPath%\

+ CategoryInfo          : ObjectNotFound: (C:\Octopus\Work...-7\%nunitPath %\:String) [Set-Location],    ItemNotFoundException 
+ FullyQualifiedErrorId :     PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

The remote script failed with exit code 1

我不明白为什么错误报告的位置与 PowerShell 脚本中指定的位置不同。 非常感谢任何帮助。

【问题讨论】:

    标签: powershell selenium selenium-webdriver continuous-integration octopus-deploy


    【解决方案1】:

    cd 是 Set-Location 的别名,因此您可以通过查看错误来判断它是您需要更改的第二行。您的 cd 行正在尝试将位置设置为 %nunitpath% 环境变量,而不是 nunitPath 脚本变量。

    要引用脚本变量,请使用 $nunitpath

    所以你的脚本应该是这样的:

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

    编辑@4c74356b41 附加正确评论。

    【讨论】:

    • set 在 powershell 中不起作用,因为它是 set-variable 的别名,应该是 set nunitPath "C:\AutomatedTests"
    • 我更改了脚本的语法,使其正确,但我仍然得到同样的错误。可能是服务器权限问题?
    • 你至少应该得到一个不同的错误你能发布吗?
    • 我解决了最新的错误,它是: ObjectNotFound: (nunit-console:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CommandNotFoundException
    • 但是,我现在遇到另一个错误:OpenQA.Selenium.WebDriverException:抛出了一个带有空响应的异常,向远程 WebDriver 服务器发送 HTTP 请求以获取 URL localhost:53393/session。底层连接已关闭:接收时发生意外错误。 ----> System.Net.WebException:底层连接已关闭:接收时发生意外错误。 ----> System.IO.IOException : Unable to read data from the transport connection: 现有连接被远程主机强行关闭。
    【解决方案2】:

    PowerShell 不使用%variablename% 语法来扩展字符串中的环境变量引用。那是 cmd.exe 语法。在 PowerShell 中,改为写 $env:variablename

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多