Tôi đang sử dụng plugin Jenkins PowerShell để tạo dự án.Plugin Jenkins powershell luôn xây dựng thành công
Tuy nhiên, tôi thấy rằng Jenkins luôn xem xét xây dựng thành công của tôi bất kể tôi nhập gì bên trong lệnh Windows PowerShell
.
Dưới đây là một ví dụ:
Như bạn thấy, asdf
không phải là một lệnh hợp pháp. Jenkins nên cho tôi FAILURE
sau khi xây dựng.
Nhưng giao diện điều khiển đầu ra mang lại cho tôi:
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
Tôi nghĩ rằng việc thực hiện kết quả của PowerShell nên phụ thuộc vào $lastexitcode
.
Đây có phải là lỗi của plugin PowerShell không?
Trong tập lệnh PowerShell của bạn khi xảy ra lỗi, hãy sử dụng "exit x" trong đó x là số khác 0. Xem nếu Jenkins xem xét nó không thành công sau đó. – DanL
Có, Jenkins coi 'thoát 1' là không thành công. – Brian
Sau đó, thay đổi tập lệnh của bạn để thoát với mã lỗi khác 0 nếu xảy ra lỗi. Nếu bạn muốn nó chỉ phụ thuộc vào $ lastexitcode thì ở cuối kịch bản của bạn kiểm tra $ lastexitcode và sử dụng exit 1 nếu có. – DanL