我们如何使用groovy脚本检查页面是否返回504。请帮忙。
我需要检查网页是否返回504,并且是否返回504,我需要使jenkins构建失败。
请帮助
答案 0 :(得分:2)
也许是这样(简单,不需要额外的依赖关系,似乎满足您的需求):
HttpURLConnection connection = new URL("http://google.com/").openConnection();
def resoponseCode = connection.getResponseCode();
connection.disconnect();
println("The response code was ${resoponseCode}")
如果google成立:-) responseCode将为200。那么您可以输入:
if (responseCode ...) {
// fail the build here
}
希望有帮助。