我在 jenkins 中运行 curl 命令,但与结果无关,jenkins 总是成功完成工作。
如何根据卷曲结果将作业状态转换为成功/失败?
这是我在 jenkins 的执行 shell 块中的 curl 请求:
curl -X GET http://api...
Run Code Online (Sandbox Code Playgroud)
Yeah, curl returns 0 exit code regardless of what happens with the request by default. You turn the job status into failure in jenkins by returning a non-zero exit code. You can achieve this in curl using the --fail option. Whenever curl sees a non-200 level http response, it returns a 22 exit status. Check it out:
~ % 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
Run Code Online (Sandbox Code Playgroud)
Some caveats at https://superuser.com/questions/590099/can-i-make-curl-fail-with-an-exitcode-different-than-0-if-the-http-status-code-i.
归档时间: |
|
查看次数: |
2002 次 |
最近记录: |