2016-11-18 228 views
0
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 
  1. 的.msi没有出现在指定的路径它去到别的和打印是什么东西。
  2. 现在我已经添加了代码EXIT 1,$ lastexitcode的值将是1.但仍然jenkins窗口powershell工作显示完成:成功。

有人可以请指出我做错了什么。我想让詹金斯的工作失败。我是詹金斯新手。

回答

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 } 

所以在詹金斯PowerShell的插件是很弱智,你必须强迫它退出代码,所以它会理解的错误。我发现工作对我来说是:

if ($error) { $error; exit 1 } 

$error是由PowerShell引擎填充的是在执行过程中出现的错误的变量。所以如果它存在>有错误>我们需要失败的构建。当然,它不适用于try \ catch块。但只是一种选择。