make groovy request accept 404 - 错误:hudson.AbortException:失败:返回的代码404不在可接受的范围内:[[100‥399]]

Neb*_*sar 3 apache groovy http-headers jenkins

我正在为我的api编写一些集成测试.现在,我想测试一个返回404的请求.这就是我想要的,但groovy/hudson总是在我尝试时将我的构建标记为失败.当然,这是因为404不在可接受的范围之间.

我明白了这个错误.问题是我不知道如何解决这个问题.

我的Groovy文件的一部分:

def testID = "fakeID"
response = httpRequest acceptType: "APPLICATION_JSON", 
          contentType: "APPLICATION_JSON",
          customHeaders: [[name: 'Authorization', value: token]],
          url: server+port+"/exams"+testID
Run Code Online (Sandbox Code Playgroud)

有谁知道如何让groovy接受这404?所有帮助都提前感谢!

Vit*_*nko 8

您可以使用validResponseCodes参数指定一系列有效的响应代码

response = httpRequest acceptType: "APPLICATION_JSON", 
          contentType: "APPLICATION_JSON",
          customHeaders: [[name: 'Authorization', value: token]],
          url: server+port+"/exams"+testID,
          validResponseCodes: '200:404'
Run Code Online (Sandbox Code Playgroud)

请参阅httpRequest文档