if (Test-Path "c:\Temp\some.msi")
{
start-process -Wait -FilePath "msiexec.exe" -ArgumentList -somearguments
}
else
{
Write-Host "MSI does not exist at the specified location....c:\Temp\"
exit 1
}
$lastexitcode
有人可以指出我做错了什么。我想要jenkins工作失败的标记。我是詹金斯的新手。
答案 0 :(得分:1)
您在退出前忘记了;
。
if (Test-Path "c:\Temp\some.msi") { start-process -Wait -FilePath "msiexec.exe" -ArgumentList -somearguments}
else { Write-Host "MSI does not exist at the specified location....c:\Temp\"; Exit 1 }
所以Jenkins中的PowerShell插件非常迟钝,你必须强制退出代码,这样才能理解错误。我发现为我工作的是:
if ($error) { $error; exit 1 }
$error
是由PowerShell引擎填充的变量,其中包含执行期间发生的错误。所以如果它存在>有错误>我们需要使构建失败。当然它不适用于try \ catch块。但作为替代方案。