Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline: GitHub plugin doesn't respect Jenkins update center proxy settings #66

Open
ababushk opened this issue Aug 12, 2019 · 4 comments · May be fixed by #92
Open

Pipeline: GitHub plugin doesn't respect Jenkins update center proxy settings #66

ababushk opened this issue Aug 12, 2019 · 4 comments · May be fixed by #92

Comments

@ababushk
Copy link

Pipeline: GitHub plugin doesn't use HTTP proxy settings which are set in Jenkins settings to connect to GitHub API.
As a workaround you should use JVM properties by passing them to Jenkins launch string:

-Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=80 -Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=443 -Dhttp.nonProxyHosts=localhost|127.0.0.1|*.example.com

or by setting them via Script Console

System.setProperty("http.proxyHost", "proxy.example.com")
System.setProperty("http.proxyPort", "80")
System.setProperty("https.proxyHost", "proxy.example.com")
System.setProperty("https.proxyPort", "443")
System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1|*.example.com")
@aaronjwhiteside
Copy link

These properties are intended for the JVM's URLConnection and don't HAVE to be honored by anything else, however I'll take a look and see what is required to have them be applied when present.

@ababushk
Copy link
Author

Hi @aaronjwhiteside, thanks for looking into this!
I think I wasn't precise in the issue description. What I meant is that usually plugins are using proxy settings provided in Jenkins Update Center, but Pipeline GitHub plugin uses standard Java system properties.
This was intended to help others in such situation.

@georgiee
Copy link

@ababushk your note about using the Script Console helped spotting the issue as we only have the Jenkins HTTP proxy settings enabled in the UI without passing the properties to JVM. I could confirm it by using the script console. Without the proxy the Plugin fails hard as the Github API is behind a authorization tenant that will return a website to login. Further debugging? Almost not possible as you would have to go on the network level or spot some log from the underlying plugins in the hope to see something from the received payload.

The error triggered through this plugin is rather cryptic while the reasons is a plain simple json error as the the API was not reachable and the returned value is the login form html page.

I think catching this error by the plugin combined with a warning, that there might be a wrong or missing proxy setting would make the developer experience much better. I have no experience with jenkins plugin development nor much java experience, so I just let this proposal here 🙏

I also let the error message here, to help people finding this issue as I wasn't able find anything on the github platform related to jenkins plugins while searching for it.

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

Here a longer exception excerpt, the full stack trace is too long and goes beyond the relevant parts I think.

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
	at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)
Caused: com.google.gson.JsonSyntaxException
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
	at com.google.gson.Gson.fromJson(Gson.java:888)
	at com.google.gson.Gson.fromJson(Gson.java:853)
	at org.eclipse.egit.github.core.client.GitHubClient.parseJson(GitHubClient.java:455)
Caused: java.io.IOException: Parse exception converting JSON to object
	at org.eclipse.egit.github.core.client.GitHubClient.parseJson(GitHubClient.java:457)
	at org.eclipse.egit.github.core.client.GitHubClient.parseJson(GitHubClient.java:436)
	at org.eclipse.egit.github.core.client.GitHubClient.parseError(GitHubClient.java:547)
	at org.eclipse.egit.github.core.client.GitHubClient.createException(GitHubClient.java:580)
	at org.eclipse.egit.github.core.client.GitHubClient.get(GitHubClient.java:778)
	at org.jenkinsci.plugins.pipeline.github.client.ExtendedGitHubClient.getUnchecked(ExtendedGitHubClient.java:79)
	at org.jenkinsci.plugins.pipeline.github.client.ExtendedPullRequestService.getPullRequest(ExtendedPullRequestService.java:80)
	at org.jenkinsci.plugins.pipeline.github.PullRequestGroovyObject.<init>(PullRequestGroovyObject.java:82)
	at org.jenkinsci.plugins.pipeline.github.PullRequestGlobalVariable.getValue(PullRequestGlobalVariable.java:30)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:135)
	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
	at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:355)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:354)
	at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:353)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:357)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:333)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
Caused: java.io.UncheckedIOException
	at org.jenkinsci.plugins.pipeline.github.client.ExtendedGitHubClient.getUnchecked(ExtendedGitHubClient.java:81)

@georgiee
Copy link

FYI there is a PR now pending fixing exactly this issue and make the plugin aware of the jenkins proxy settings 💪 It's already linked to this issues #92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants