在詹金斯的失败/成功中转换卷曲请求作业

Fil*_*ano 2 curl jenkins

我在 jenkins 中运行 curl 命令,但与结果无关,jenkins 总是成功完成工作。

如何根据卷曲结果将作业状态转换为成功/失败?

这是我在 jenkins 的执行 shell 块中的 curl 请求:

curl -X GET http://api...
Run Code Online (Sandbox Code Playgroud)

bur*_*ttk 5

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.