jenkinsci / service-now-plugin

Build Jenkins workflow steps for the service-now API
https://plugins.jenkins.io/service-now/
MIT License
26 stars 32 forks source link

Doesn't work with proxy ? #14

Open mikador opened 5 years ago

mikador commented 5 years ago

Hi,

From our Jenkins machine we need to connect to the outside world via proxy. I'm trying to use this plugin but does anyone have it working in such configuration or has it some issue?

When I do curl from bash command to service-now instance, all looks ok :

Host: sabretest.service-now.com Accept: / HTTP/1.1 302 Found

but when I try to use the plugin to create change based on template (producerId) in Jenkins pipeline this way:

import groovy.json.JsonSlurper
node {  
    stage('SabreTest_SNOW') {
         def response = serviceNow_createChange serviceNowConfiguration: [instance: 'sabretest', producerId: 'e03af10513cfe3c0a7b276d66144b0'], credentialsId: 'servicenow_test'
         def jsonSlurper = new JsonSlurper()
         def createResponse = jsonSlurper.parseText(response.content)
         def sysId = createResponse.result.sys_id
         def changeNumber = createResponse.result.number
    }
}

I'm getting this:

[Pipeline] { [Pipeline] stage [Pipeline] { (SabreTest_SNOW) [Pipeline] serviceNow_createChange [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline hudson.remoting.ProxyException: java.net.ConnectException: Connection timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) Caused: hudson.remoting.ProxyException: org.apache.http.conn.ConnectTimeoutException: Connect to sabretest.service-now.com:443 [sabretest.service-now.com/149.96.22.136] failed: Connection timed out at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:157) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.jenkinsci.plugins.servicenow.ServiceNowExecution.sendRequest(ServiceNowExecution.java:117) at org.jenkinsci.plugins.servicenow.ServiceNowExecution.createChange(ServiceNowExecution.java:78) at org.jenkinsci.plugins.servicenow.workflow.CreateChangeStep$Execution.run(CreateChangeStep.java:78) at org.jenkinsci.plugins.servicenow.workflow.CreateChangeStep$Execution.run(CreateChangeStep.java:49) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$$Lambda$127/1167650417.run(Unknown Source) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Finished: FAILURE

It cannot connect to service-now.com. What would be the way to solve that? Can anyone help please?

jmcshane commented 5 years ago

@mikador Do you have other java applications in your environment that are configured to deal with this proxy? I have to admit I have limited experience dealing with proxies like this, especially from Jenkins itself.

jmcshane commented 4 years ago

Figured I should take a look at this. I checked out some of the apache code for using a request proxy, looks like we need to create a RequestConfig object here: https://hc.apache.org/httpcomponents-client-4.5.x/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java.

I think this would make sense in the global plugin configuration object, potentially putting something optional in here: https://github.com/jenkinsci/service-now-plugin#required-parameters.

I'll take a look this weekend if I have a chance.

mustafic commented 4 years ago

Just created a PR for this. My tests were successful ☺️