私はJenkins PowerShellプラグインを使用してプロジェクトをビルドしています。Jenkins powershellプラグインは常に正常に構築されます
しかし、私はWindows PowerShell
コマンドを入力しても、ジェンキンスは常に自分のビルドを成功と見なしていることがわかりました。
あなたが見ることができるように、asdf
は法的なコマンドではありません。
は、ここでの例です。ジェンキンスは、ビルド後に私にFAILURE
を与える必要があります。
しかし、コンソール出力は、私を与える:
Started by user admin
Building in workspace C:\Users\Administrator\.jenkins\jobs\Test\workspace
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1'"
The term 'asdf' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1:1 char:5
+ asdf <<<<
+ CategoryInfo : ObjectNotFound: (asdf:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Finished: SUCCESS
私はPowerShellのの実行結果が$lastexitcode
に依存すべきだと思います。
これはPowerShellプラグインのバグですか?
エラーが発生した場合のpowershellスクリプトでは、 "exit x"を使用してください。ここで、xはゼロ以外の数字です。それが失敗したとジェンキンスが考えるかどうかを見てください。 – DanL
はい、Jenkinsは 'exit 1'を失敗とみなします。 – Brian
エラーが発生した場合は、スクリプトをゼロ以外のエラーコードで終了するように変更します。 $ lastexitcodeだけに依存したい場合は、スクリプトの最後に$ lastexitcodeをチェックし、該当する場合はexit 1を使用します。 – DanL