0

I have following method in Jenkinsfile used to retrieve data from given URL (posting json to it and reading the output). Calling it in Jenkins causes the build to hang with *Proceeding.." text.

@NonCPS                                                      
def callService(server, method, params = '') {                                  
    final HttpURLConnection connection = "http://$server:8080/router/".toURL().openConnection()
    connection.setRequestMethod("POST");                                        
    connection.setRequestProperty('Accept', 'application/json;charset=utf-8')   
    connection.setRequestProperty('Content-Type', 'application/json;charset=utf-8')
    connection.setDoOutput(true)                                                
    connection.outputStream.withWriter { Writer writer ->                       
        writer << """{"jsonrpc": "2.0", "method": "$method", "params": {$params}}"""
    }                                                                           
    String text = connection.inputStream.withReader { Reader reader -> reader.text }
    return text                                                                                                                                                                               
}                                                                               

And the call of this method:

servers = ["example1"]
for (int i = 0; i < servers.size(); i++) {                                  
    server = servers[i]                                                     
    assert callService(server, 'VersionService:getVersionDetails').matches('.*build:[1-9][0-9]*.*') 
}   

Is the above code correct groovy one, or am I doing something wrong that causes the code to freeze?

When I do the same thing using curl, it works:

curl -v -H 'Accept: application/json;charset=utf-8' -H 'Content-Type: application/json;charset=utf-8' -d '{"jsonrpc": "2.0", "method":"VersionService:getVersionDetails", "params":{}}' http://example1:8080/router/
4

1 に答える 1