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

server api url is ignored - plugin still tries api.github.com #32

Closed
highlycaffeinated opened this issue Feb 21, 2013 · 16 comments
Closed

Comments

@highlycaffeinated
Copy link

Settings are correct for github project url and server api url - both point to github enterprise server. Plugin still tries to use api.github.com:

Feb 20, 2013 10:50:27 PM org.jenkinsci.plugins.ghprb.GhprbRepo checkState
SEVERE: Could not retrieve repo named MyOrg/sandbox (Do you have properly set 'GitHub project' field in job configuration?)
java.io.IOException: {"message":"Bad credentials"}
at org.kohsuke.github.Requester.handleApiError(Requester.java:341)
at org.kohsuke.github.Requester._to(Requester.java:175)
at org.kohsuke.github.Requester.to(Requester.java:139)
at org.kohsuke.github.GitHub.getRepository(GitHub.java:250)
at org.jenkinsci.plugins.ghprb.GhprbRepo.checkState(GhprbRepo.java:78)
at org.jenkinsci.plugins.ghprb.GhprbRepo.check(GhprbRepo.java:91)
at org.jenkinsci.plugins.ghprb.GhprbTrigger.run(GhprbTrigger.java:132)
at hudson.triggers.Trigger.checkTriggers(Trigger.java:261)
at hudson.triggers.Trigger$Cron.doRun(Trigger.java:209)
at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://api.github.com/repos/MyOrg/sandbox
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at org.kohsuke.github.Requester.parse(Requester.java:297)
at org.kohsuke.github.Requester._to(Requester.java:173)
... 10 more
Feb 20, 2013 10:50:27 PM org.jenkinsci.plugins.ghprb.GhprbRepo checkState
SEVERE: Could not retrieve repo named MyOrg/sandbox (Do you have properly set GitHub project field in job configuration?)

@janinko
Copy link
Owner

janinko commented Feb 22, 2013

Are you using Access Token?

@highlycaffeinated
Copy link
Author

No, I'm not using an access token. Just username and password.

@leftathome
Copy link

I'm seeing the same thing. I've had this issue on an older version of the plugin (~ 1.3?), but just decided to devote a few hours to trying to get it to work. I've updated to the latest versions of the dependent git/github API plugins to rule that out as an issue.

I'll try it with a token and see if it works...

@leftathome
Copy link

Okay, yeah, it queried the right API endpoint once I put in the token, but oddly enough it seems to be defaulting to http instead of https in checkMergeable and that makes my transparent proxy sad:

Feb 25, 2013 2:46:23 PM org.jenkinsci.plugins.ghprb.GhprbPullRequest checkMergeable
SEVERE: Couldn't obtain mergeable status.
java.io.IOException: [text of 403 error]
    at org.kohsuke.github.Requester.handleApiError(Requester.java:341)
    at org.kohsuke.github.Requester._to(Requester.java:175)
    at org.kohsuke.github.Requester.to(Requester.java:146)
    at org.kohsuke.github.GHPullRequest.populate(GHPullRequest.java:182)
    at org.kohsuke.github.GHPullRequest.getMergeable(GHPullRequest.java:155)
    at org.jenkinsci.plugins.ghprb.GhprbPullRequest.checkMergeable(GhprbPullRequest.java:166)
    at org.jenkinsci.plugins.ghprb.GhprbPullRequest.check(GhprbPullRequest.java:61)
    at org.jenkinsci.plugins.ghprb.GhprbRepo.check(GhprbRepo.java:111)
    at org.jenkinsci.plugins.ghprb.GhprbTrigger.run(GhprbTrigger.java:132)
    at hudson.triggers.Trigger.checkTriggers(Trigger.java:261)
    at hudson.triggers.Trigger$Cron.doRun(Trigger.java:209)
    at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
    at java.util.TimerThread.mainLoop(Timer.java:534)
    at java.util.TimerThread.run(Timer.java:484)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://{my github enterprise}/api/v3/repos/{my org}/{my repo}/pulls/3?access_token={my token}
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1403)
    at org.kohsuke.github.Requester.parse(Requester.java:297)
    at org.kohsuke.github.Requester._to(Requester.java:173)
    ... 12 more

@leftathome
Copy link

BTW, if the Internet is interested, I generated my token using this awesome API call in curl:

curl -u 'GitHubUser:GitHubPassword' -d '{"scopes":["repos"],"note":"pull request builder"}' \
https://{my github endpoint}/api/v3/authorizations

@janinko
Copy link
Owner

janinko commented Feb 26, 2013

Kohsuke's github api library I'm using doesn't support username:password based connection to enterprise servers.

So you need to use access token with enterprise servers.

@janinko
Copy link
Owner

janinko commented Feb 27, 2013

@leftathome I think that the issue is the response from server contains wrong url.
If you try something like this:

curl https://{my github enterprise}/api/v3/repos/{my org}/{my repo}/pulls/3?access_token={my token}

you get

{
  "url": "https://{my github enterprise}/api/v3/repos/{my org}/{my repo}/pulls/3",
  ...

or

{
  "url": "http://{my github enterprise}/api/v3/repos/{my org}/{my repo}/pulls/3",
  ...

?

Kohsuke's library is using the url it gets from the response.

@highlycaffeinated
Copy link
Author

I switched to using tokens and I am working now.

@wsoula
Copy link

wsoula commented Mar 11, 2013

Where do the tokens go? I tried putting it in the password field on the configure page for Jenkins, but am getting the same error. Is it a problem that our user names are [username]@[domain].com and then in github we have just [username] shown? I.e. we log in with [username]@[domain].com and my repo is at [gitserver]/[username]/[repo]. I was having the same error as this issue so I got a token generated and now I am getting this error:
Mar 11, 2013 11:09:09 AM hudson.triggers.Trigger checkTriggers
WARNING: org.jenkinsci.plugins.ghprb.GhprbTrigger.run() failed for test-github-pull-request-builder
java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic d2lsbGlhbS5zb3VsYUBuYS5kcmlsbGluZ2luZm8uY29tOmRmNmE0ZDQxYTQ0Y2ExZTQxMDhjNTdh
NWY4NzY5Yzc2YjlkNjE2MDE=
at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:440)
at sun.net.www.protocol.http.HttpURLConnection.isExternalMessageHeaderAllowed(HttpURLConnection.java:406)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:2288)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:316)
at org.kohsuke.github.Requester.setupConnection(Requester.java:272)
at org.kohsuke.github.Requester._to(Requester.java:155)
at org.kohsuke.github.Requester.to(Requester.java:135)
at org.kohsuke.github.GitHub.getUser(GitHub.java:194)
at org.kohsuke.github.GitHub.getRepository(GitHub.java:230)
at org.jenkinsci.plugins.ghprb.GhprbRepo.checkState(GhprbRepo.java:78)
at org.jenkinsci.plugins.ghprb.GhprbRepo.check(GhprbRepo.java:91)
at org.jenkinsci.plugins.ghprb.GhprbTrigger.run(GhprbTrigger.java:132)
at hudson.triggers.Trigger.checkTriggers(Trigger.java:261)
at hudson.triggers.Trigger$Cron.doRun(Trigger.java:209)
at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
at java.util.TimerThread.mainLoop(Timer.java:534)
at java.util.TimerThread.run(Timer.java:484)

@highlycaffeinated
Copy link
Author

In Jenkins / Manage Jenkins / System Configuration, under Github pull request builder, click the 'Advanced' button. The last field is for access token.

@wsoula
Copy link

wsoula commented Mar 11, 2013

Thank you so much for the quick reply, especially on a closed issue. I can't believe I didn't see that advanced button, d'oh! Now I am getting the following stack trace:
Mar 11, 2013 12:34:14 PM org.jenkinsci.plugins.ghprb.GhprbRepo connect
SEVERE: Can't connect to https://[gitHubServer]/api/v3 using oauth
java.net.UnknownHostException: api.https
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:175)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:584)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
at sun.net.NetworkClient.doConnect(NetworkClient.java:178)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:275)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:332)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:876)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.kohsuke.github.Requester.parse(Requester.java:293)
at org.kohsuke.github.Requester._to(Requester.java:169)
at org.kohsuke.github.Requester.to(Requester.java:135)
at org.kohsuke.github.GitHub.getMyself(GitHub.java:180)
at org.kohsuke.github.GitHub.(GitHub.java:103)
at org.kohsuke.github.GitHub.connectUsingOAuth(GitHub.java:134)
at org.jenkinsci.plugins.ghprb.GhprbRepo.connect(GhprbRepo.java:61)
at org.jenkinsci.plugins.ghprb.GhprbRepo.(GhprbRepo.java:45)
at org.jenkinsci.plugins.ghprb.GhprbTrigger.start(GhprbTrigger.java:81)
at org.jenkinsci.plugins.ghprb.GhprbTrigger.start(GhprbTrigger.java:37)
at hudson.model.AbstractProject.submit(AbstractProject.java:1916)
at hudson.model.Project.submit(Project.java:195)
at hudson.model.Job.doConfigSubmit(Job.java:1070)
at hudson.model.AbstractProject.doConfigSubmit(AbstractProject.java:740)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:288)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:151)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:90)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:111)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:573)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:658)
at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:241)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:573)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:658)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:487)
at org.kohsuke.stapler.Stapler.service(Stapler.java:164)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
at winstone.ServletConfiguration.execute(ServletConfiguration.java:248)
at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:376)
at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:95)
at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:87)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:47)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:124)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:174)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at jenkins.security.ApiTokenFilter.doFilter(ApiTokenFilter.java:64)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:66)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:50)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:194)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:366)
at winstone.RequestDispatcher.forward(RequestDispatcher.java:331)
at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:227)
at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)

@wsoula
Copy link

wsoula commented Mar 11, 2013

my previous value for github server api url was https://[githubServer]/api/v3. I changed it to [githubServer]/api/v3 and the stack trace now complained about api.[githubServer] instead of api.https, so it looks like it still thinks it is a github web server instead of github enterprise.

@highlycaffeinated
Copy link
Author

The url you're using looks correct to me. I'm using https://[github.my.org]/api/v3 for mine.

@wsoula
Copy link

wsoula commented Mar 11, 2013

Could it be that our github site's certificate is self-signed and not great? By that I mean I had to pass the -k option to curl in order to create my access token. Or is it the difference in usernames, i.e. login with [username]@[domain].com and repos are created at [githubServer]/[username]/[reponame]? I'm guessing the error thrown is wrong like it is when you try to use the username and password with no access token for a github enterprise server.

@highlycaffeinated
Copy link
Author

For my github, we login with a non-email address login, i.e. something like 'myusername' and our repos are created in the same pattern as you mention. Can't weigh in on the self-signed cert though, as ours was issued by a CA. Hope that helps!

@wsoula
Copy link

wsoula commented Mar 20, 2013

Hey, I wanted to close the loop now that I got it working. I upgraded some of the git plugins like github api, github, ghprb, git and the like and the logging was improved so I got the below error which looked suspiciously like the self signed cert of my github enterprise was the problem and with some googling I found that I was right and this page provided an easy work around: http://www.erikzaadi.com/2011/09/09/connecting-jenkins-to-self-signed-certificated-servers/

Mar 20, 2013 8:07:25 AM org.jenkinsci.plugins.ghprb.GhprbRepo connect
SEVERE: Can't connect to https://[gitServer]/api/v3 using oauth
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1697)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:257)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:251)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1165)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:609)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:545)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:945)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1190)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1217)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1201)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:440)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.kohsuke.github.Requester.parse(Requester.java:297)
at org.kohsuke.github.Requester._to(Requester.java:173)
at org.kohsuke.github.Requester.to(Requester.java:139)
at org.kohsuke.github.GitHub.getMyself(GitHub.java:200)
at org.kohsuke.github.GitHub.(GitHub.java:102)
at org.kohsuke.github.GitHub.connectUsingOAuth(GitHub.java:149)
at org.jenkinsci.plugins.ghprb.GhprbRepo.connect(GhprbRepo.java:61)
at org.jenkinsci.plugins.ghprb.GhprbRepo.checkState(GhprbRepo.java:73)
at org.jenkinsci.plugins.ghprb.GhprbRepo.check(GhprbRepo.java:91)
at org.jenkinsci.plugins.ghprb.GhprbTrigger.run(GhprbTrigger.java:132)
at hudson.triggers.Trigger.checkTriggers(Trigger.java:261)
at hudson.triggers.Trigger$Cron.doRun(Trigger.java:209)
at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:54)
at java.util.TimerThread.mainLoop(Timer.java:534)
at java.util.TimerThread.run(Timer.java:484)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:324)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:224)
at sun.security.validator.Validator.validate(Validator.java:235)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:147)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:230)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:270)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1144)
... 26 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:197)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:255)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:319)
... 32 more

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

No branches or pull requests

4 participants