2017-04-23 44 views

回答

3

呀,捲曲的回報,無論用什麼默認的請求,結果會退出代碼0。您通過返回非零退出代碼將作業狀態轉換爲jenkins中的失敗。你可以使用--fail選項在curl中實現這一點。每當curl看到非200級別的http響應時,它將返回22退出狀態。檢查出來:

~ % curl --silent --fail http://httpstat.us/200 > /dev/null; echo $? 
0 
~ % curl --silent --fail http://httpstat.us/401 > /dev/null; echo $? 
22 
~ % curl --silent --fail http://httpstat.us/500 > /dev/null; echo $? 
22 

一些注意事項https://superuser.com/questions/590099/can-i-make-curl-fail-with-an-exitcode-different-than-0-if-the-http-status-code-i