为什么我在Jenkins管道中收到请求超时?

为什么我在Jenkins管道中收到请求超时?,jenkins,jenkins-pipeline,httprequest,Jenkins,Jenkins Pipeline,Httprequest,我创建了一个管道,在部署后通过http请求对我部署的2个应用程序的info端点进行“冒烟测试”。 我做了3次重试,因为有一次请求超时。 但这3次重试仍然不够——因此管道有点“崩溃” 这是我的密码: void smoketests() { retry(3) { try { SMOKE_TEST_PORTS.each { port -> String url = isReleaseBranch() ? &quo

我创建了一个管道,在部署后通过http请求对我部署的2个应用程序的info端点进行“冒烟测试”。 我做了3次重试,因为有一次请求超时。 但这3次重试仍然不够——因此管道有点“崩溃”

这是我的密码:

void smoketests() {
  retry(3) {
    try {
      SMOKE_TEST_PORTS.each {
        port ->
          String url = isReleaseBranch() ?
            "https://<url>:${port}/actuator/info" :
            "http://<url>:${port}/actuator/info"
          def responseJson = readJSON(text:
            httpRequest(consoleLogResponseBody: true, timeout: 60, httpMode: 'GET', ignoreSslErrors: true, url: url)
          .content)
        if (!responseJson.build.version.equals(POM.getVersion())) {
          throw new Exception("Not expected version number (${responseJson.build.version})")
        }
    }
  } catch (err) {
    println err
    sleep(time: 20, unit: 'SECONDS')
    throwError('can\'t reach health endpoint(s) or not expected version number')
  }
}
if (isReleaseBranch()) {
  sendMattermostMsg("released ${PROJECT} with version ${POM.getVersion()} on UAT")
}
void-smoketests(){
重试(3){
试一试{
烟雾测试各端口{
端口->
字符串url=isReleaseBranch()?
“https://:${port}/activator/info”:
“http://:${port}/activator/info”
def responseJson=readJSON(文本:
httpRequest(consoleLogResponseBody:true,超时:60,httpMode:'GET',ignoreSslErrors:true,url:url)
(1.内容)
如果(!responseJson.build.version.equals(POM.getVersion())){
引发新异常(“不需要版本号(${responseJson.build.version})”)
}
}
}捕捉(错误){
打印错误
睡眠(时间:20,单位:秒)
throwError('无法到达运行状况终结点或不是预期的版本号')
}
}
if(isReleaseBranch()){
sendMattermostMsg(“在UAT上发布了版本为${POM.getVersion()}的${PROJECT}”)
}
}

所以我现在加了一个60秒的超时时间,但有时还是会崩溃。但是可以通过浏览器访问端点。管道代码中有我的错误吗

以下是日志:

HttpMethod: GET
URL: https://<url>:11761/actuator/info
Sending request to url: https://<url>:11761/actuator/info
Treating class org.apache.http.conn.HttpHostConnectException(Connect to 
<url>:11761 [<url>] failed: Connection refused (Connection refused)) as 408 Request Timeout
Response: 
class org.apache.http.conn.HttpHostConnectException(Connect to <url>:11761 [<url>] failed: Connection 
refused (Connection refused)) as 408 Request Timeout
[Pipeline] echo
java.lang.IllegalStateException: hudson.AbortException: Fail: the returned code 408 is not in the accepted range: [[100‥399]]
[Pipeline] sleep
Sleeping for 20 sec
... etc.
HttpMethod:GET
URL:https://:11761/exactuator/info
将请求发送到url:https://:11761/exactuator/info
处理类org.apache.http.conn.HttpHostConnectException(连接到
:11761[]失败:连接被拒绝(连接被拒绝))作为408请求超时
答复:
类org.apache.http.conn.HttpHostConnectException(连接到:11761[]失败:连接
拒绝(连接被拒绝))作为408请求超时
[管道]回声
java.lang.IllegalStateException:hudson.AbortException:Fail:返回的代码408不在可接受的范围内:[[100--399]]
[管道]睡眠
睡20秒
... 等

您是否支持公司代理?我花了很多时间试图找到代理身份验证的正确语法

如果是这样的话,像这样的东西可能会对你有用:

def response = httpRequest url: "http://postman-echo.com/get?test=123", httpProxy: "http://proxy.yourcompany.com:8080", customHeaders: [[name: 'Proxy-Authorization', value: 'Basic xxxxxxxxxxxxxxxxx', maskValue: true]]

要获取“XXXXXXXXXXXXXX”的值,请以以下格式在浏览器中键入代理凭据:javascript:btoa(“用户名:密码”)

您是否支持公司代理?我花了很多时间试图找到代理身份验证的正确语法

如果是这样的话,像这样的东西可能会对你有用:

def response = httpRequest url: "http://postman-echo.com/get?test=123", httpProxy: "http://proxy.yourcompany.com:8080", customHeaders: [[name: 'Proxy-Authorization', value: 'Basic xxxxxxxxxxxxxxxxx', maskValue: true]]
要获取“XXXXXXXXXXXXXX”的值,请在浏览器中以以下格式键入代理凭据:javascript:btoa(“用户名:密码”)