【问题标题】:Is there any way to return the failure from a PowerShell script into azure CLi?有没有办法将 PowerShell 脚本的失败返回到 azure CLi?
【发布时间】:2021-02-03 07:25:31
【问题描述】:

我正在尝试构建一个控制 Azure 中的 Windows 虚拟机的 Jenkins 管道。我需要使用 Azure CLI 在该 VM 上运行一些 Powershell 脚本。我遇到的问题是,即使 PowerShell 脚本失败,Azure CLI 也会成功返回操作。

这是脚本失败且管道通过时的运行:

{
  "value": [
    {
      "code": "ComponentStatus/StdOut/succeeded",
      "displayStatus": "Provisioning succeeded",
      "level": "Info",
      "message": "Uninstalling the previous version\n\nCheck that the previous installer was uninstalled\n\n'App' NOT is installed.\n",
      "time": null
    },
    {
      "code": "ComponentStatus/StdErr/succeeded",
      "displayStatus": "Provisioning succeeded",
      "level": "Info",
      "message": "C:\\Location\\clean_up.ps1 : Exception of type \n'Microsoft.PowerShell.Commands.WriteErrorException' was thrown.\nAt C:\\Packages\\Plugins\\Microsoft.CPlat.Core.RunCommandWindows\\1.1.5\\Downloads\\script49.ps1:1 char:1\n+ & C:\\Location\\clean_up.ps1\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException\n    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,clean_up.ps1\n ",
      "time": null
    }
  ]
}

我无法找到任何方法将错误从 PowerShell 返回到管道,从而导致管道无法使用。有什么办法可以让 Jenkins Pipeline 失败吗?

【问题讨论】:

    标签: azure powershell jenkins


    【解决方案1】:

    如果可能,更好的选择是使用 Azure PowerShell。但是,在当前情况下,要从 PowerShell 返回实际代码,请查看 this 是否有帮助。

    【讨论】:

    • 感谢您的回答。我无法使用 Azure CLI 和 Jenkins 发送类似于 powershell.exe -Command ". C:\MyScript.ps1; exit $LASTEXITCODE" 的内容。尝试在我的 docker-compose 中启动 Azure Powershell 似乎比预期的要困难。
    猜你喜欢
    • 1970-01-01
    • 2021-10-29
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 2020-09-30
    • 2016-03-01
    • 1970-01-01
    相关资源
    最近更新 更多