Powershell 如何在Jenkins构建中检测NuGet pack中的错误?

Powershell 如何在Jenkins构建中检测NuGet pack中的错误?,powershell,jenkins,nuget,Powershell,Jenkins,Nuget,我正在使用nuget.exe pack从Powershell脚本在Jenkins服务器上构建nuget包: & "C:\Git\packages\nuget.exe" pack -Build -ForceEnglishOutput -Prop Configuration=Release -IncludeReferencedProjects -OutputDirectory "c:\git\Packages" -Verbosity quiet 这将在当前文件夹中编译csproj,并将编译

我正在使用nuget.exe pack从Powershell脚本在Jenkins服务器上构建nuget包:

& "C:\Git\packages\nuget.exe" pack -Build -ForceEnglishOutput -Prop Configuration=Release -IncludeReferencedProjects -OutputDirectory "c:\git\Packages" -Verbosity quiet
这将在当前文件夹中编译csproj,并将编译后的.nupkg放入“c:\git\packages”文件夹。但是,如果构建失败了,我怎么能告诉Jenkins它失败了?在Jenkins中,我通过“执行Windows批处理命令”执行上述脚本:

powershell -File Pack.ps1

它有一个ERRORLEVEL属性来设置build不稳定,但是如何在powershell脚本中设置它?我在nuget.exe上找不到与此相关的任何文档:当前,如果构建失败,Jenkins将继续进行。这应该和添加一样简单

Exit $LASTEXITCODE
到powershell脚本的结尾

请参阅此处有关返回错误代码的详细信息