Kwo*_*rks 5 shell curl jenkins
该脚本应检查 URL 的 Http 状态代码,并在状态代码不匹配时显示错误,例如。200. 在 Jenkins 中,如果此脚本失败,则构建应该失败,并且通过构建后程序触发邮件。
另一个有趣的特性curl是它的-f/--fail选项。如果设置,它将告诉curl在任何 HTTP 错误时失败,即curl如果服务器响应状态代码不是 1xx/2xx/3xx,即如果它是 4xx 或更高,则退出代码将不同于 0,所以
curl --silent --fail "http://www.example.org/" >/dev/null
Run Code Online (Sandbox Code Playgroud)
或(相当于):
curl -sf "http://www.example.org/" >/dev/null
Run Code Online (Sandbox Code Playgroud)
如果无法找到 URL 或发生其他一些 HTTP 错误,则退出代码将为 22 而不是 0。有关的各种退出代码man curl的说明,请参见curl。
您可以使用此答案中提到的简单 shell 命令
curl -s -o /dev/null -w "%{http_code}" http://www.example.org/
Run Code Online (Sandbox Code Playgroud)
如果添加以下 shell 脚本,就会发生这种情况:
response=$(curl -s -o /dev/null -w "%{http_code}\n" http://www.example.org/)
if [ "$response" != "200" ]
then
exit 1
fi
Run Code Online (Sandbox Code Playgroud)
exit 1将把构建标记为失败
| 归档时间: |
|
| 查看次数: |
46578 次 |
| 最近记录: |