ghprb-plugin icon indicating copy to clipboard operation
ghprb-plugin copied to clipboard

"target_url must use http(s) scheme"

Open dpetzel opened this issue 9 years ago • 9 comments

I've recently upgraded Jenkins to 1.609.3 and this plugin to 1.29.2 and I'm getting the error below. I can see that it properly adds a comment when the build starts with a link to the build. The permissions seem correct (and worked before we upgraded)

I've been through the settings and everything looks right to me, but the message is pretty clear that it doesn't like the value being passed for target_url which I presume is null based on the log message. I'm pretty stumped on where to look next. Any help would be appreciated.

Build step 'Execute shell' marked build as failure
Setting status of GUID to FAILURE with url nulljob/MYORG/job/MYREPO/job/MYREPO-pr/30/ and message: 'Build finished. No test results found.'
Could not update commit status of the Pull Request on GitHub.
java.io.IOException: {"message":"Validation Failed","errors":[{"resource":"Status","code":"custom","field":"target_url","message":"target_url must use http(s) scheme"}],"documentation_url":"https://developer.github.com/enterprise/2.2/v3/repos/statuses/#create-a-status"}
    at org.kohsuke.github.Requester.handleApiError(Requester.java:503)
    at org.kohsuke.github.Requester._to(Requester.java:248)
    at org.kohsuke.github.Requester.to(Requester.java:194)
    at org.kohsuke.github.GHRepository.createCommitStatus(GHRepository.java:829)
    at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.createCommitStatus(GhprbSimpleStatus.java:213)
    at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.onBuildComplete(GhprbSimpleStatus.java:181)
    at org.jenkinsci.plugins.ghprb.GhprbBuilds.onCompleted(GhprbBuilds.java:180)
    at org.jenkinsci.plugins.ghprb.GhprbBuildListener.onCompleted(GhprbBuildListener.java:32)
    at org.jenkinsci.plugins.ghprb.GhprbBuildListener.onCompleted(GhprbBuildListener.java:17)
    at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:199)
    at hudson.model.Run.execute(Run.java:1783)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:381)
Caused by: java.io.IOException: Server returned HTTP response code: 422 for URL: https://github.internal/api/v3/repos/MYORG/MYREPO/statuses/GUID
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1676)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1674)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1672)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.kohsuke.github.Requester.parse(Requester.java:458)
    at org.kohsuke.github.Requester._to(Requester.java:227)
    ... 12 more
Caused by: java.io.IOException: Server returned HTTP response code: 422 for URL: https://github.internal/api/v3/repos/MYORG/MYREPO/statuses/GUID
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
    at org.kohsuke.github.Requester.parse(Requester.java:454)
    ... 13 more

dpetzel avatar Oct 20 '15 01:10 dpetzel

@dpetzel I am fighting a similar issue with the url. With 1.29.2 you can pass the status-url as --none-- which stops the error but you lose the link on the pull request.

I have been trying to set status-url to the $BUILD_URL but it doesn't seem to be getting evaluated as a variable.

kpettijohn avatar Oct 28 '15 16:10 kpettijohn

Can you post your config.xml for the job?

DavidTanner avatar Oct 30 '15 21:10 DavidTanner

My problem was with the $BUILD_URL not being available unless you have Jenkins -> configuration -> Global properties -> Environment variables enabled.

I have also see some cases where not all of the ghprb's global configuration is available unless you open and save the Jenkins -> configuration page.

For example the following at times would result in githubAuth being null, but only on the first converge.

import java.lang.reflect.Field
import jenkins.model.*
import org.jenkinsci.plugins.ghprb.*

def descriptor = Jenkins.instance.getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)

Field auth = descriptor.class.getDeclaredField("githubAuth")

auth.setAccessible(true)

githubAuth = auth.get(descriptor)
githubAuth.add(new GhprbGitHubAuth("<%= @server %>", "<%= @credentials_id %>", "<%= @description %>", "<%= @auth_id %>", null)

Error:

       STDERR: java.lang.NullPointerException: Cannot invoke method add() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at RemoteClass.run(RemoteClass:14)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
        at groovy.lang.GroovyShell.run(GroovyShell.java:517)
        at hudson.cli.GroovyCommand.run(GroovyCommand.java:94)
        at hudson.cli.CLICommand.main(CLICommand.java:237)
        at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:92)
        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:606)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:320)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:295)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:254)
        at hudson.remoting.UserRequest.perform(UserRequest.java:121)
        at hudson.remoting.UserRequest.perform(UserRequest.java:49)
        at hudson.remoting.Request$2.run(Request.java:324)
        at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
        at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:63)
        at hudson.remoting.CallableDecoratorAdapter.call(CallableDecoratorAdapter.java:18)
        at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21)
        at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

If you visit the Jenkins -> configuration page and hit apply/save you will no longer receive the null value.

kpettijohn avatar Oct 30 '15 21:10 kpettijohn

I am not using Jenkins, but I am seeing the exact same issue, but randomly. I am making a call to the status api. The same url, changing the status from pending to success or other, will fail with a 422 20% of the time. I have noticed it just started hitting us harder and harder over the last day or two.

m2bright avatar Nov 03 '15 15:11 m2bright

Hi, I also encountered the same problem, the stacktrace is below.

GitHub pull request #333 of commit a3812f1cd5de29ac9f71b526ca093c8d88374321, no merge conflicts.
Setting status of a3812f1cd5de29ac9f71b526ca093c8d88374321 to PENDING with url nulljob/MY-CI-JOB/480/ and message: 'Build started sha1 is merged.'
Could not update commit status of the Pull Request on GitHub.
org.kohsuke.github.HttpException: {"message":"Validation Failed","errors":[{"resource":"Status","code":"custom","field":"target_url","message":"target_url must use http(s) scheme"}],"documentation_url":"https://developer.github.com/v3/repos/statuses/#create-a-status"}
    at org.kohsuke.github.Requester.handleApiError(Requester.java:669)
    at org.kohsuke.github.Requester._to(Requester.java:284)
    at org.kohsuke.github.Requester.to(Requester.java:225)
    at org.kohsuke.github.GHRepository.createCommitStatus(GHRepository.java:1000)
    at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.createCommitStatus(GhprbSimpleStatus.java:273)
    at org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus.onBuildStart(GhprbSimpleStatus.java:186)
    at org.jenkinsci.plugins.ghprb.GhprbBuilds.onStarted(GhprbBuilds.java:132)
    at org.jenkinsci.plugins.ghprb.GhprbBuildListener.onStarted(GhprbBuildListener.java:24)
    at org.jenkinsci.plugins.ghprb.GhprbBuildListener.onStarted(GhprbBuildListener.java:17)
    at hudson.model.listeners.RunListener.fireStarted(RunListener.java:240)
    at hudson.model.Run.execute(Run.java:1725)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: org.kohsuke.github.HttpException: Server returned HTTP response code: 422, message: 'Unprocessable Entity' for URL: https://api.github.com/repos/MY-ORG/MY-REPO/statuses/a3812f1cd5de29ac9f71b526ca093c8d88374321
    at org.kohsuke.github.Requester.parse(Requester.java:613)
    at org.kohsuke.github.Requester._to(Requester.java:263)
    ... 12 more
Caused by: java.io.IOException: Server returned HTTP response code: 422 for URL: https://api.github.com/repos/MY-ORG/MY-REPO/statuses/a3812f1cd5de29ac9f71b526ca093c8d88374321
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1677)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1675)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1673)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1246)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.kohsuke.github.Requester.parse(Requester.java:597)
    ... 13 more
Caused by: java.io.IOException: Server returned HTTP response code: 422 for URL: https://api.github.com/repos/MY-ORG/MY-REPO/statuses/a3812f1cd5de29ac9f71b526ca093c8d88374321
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1628)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
    at org.kohsuke.github.Requester.parse(Requester.java:587)
    ... 13 more

In my case, after resaving "Configure System", the job works well. I hope this information will be helpful for you.

[System Info] Update Jenkins 2.24 to 2.42 Update GitHub Pull Request Builder 1.33.1 to 1.34.0 OS: CentOS6.6

civitaspo avatar Jan 25 '17 01:01 civitaspo

It seems the <secret></secret> part of ~/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml is automatically set to something (the correct something), when you visit the Jenkins -> configuration page and hit apply/save, as @kpettijohn noted, which makes the problem go away.

I'm currently adding the secret text credential to Jenkins, as well as setting up the GH PR builder plugin with a .groovy script . I tried using the same secret for both constructors, but it's apparently not the correct string that eventually ends up in the <secret> tag in ~/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml.

If I manually visit the Jenkins -> configuration page and hit apply/save, as @kpettijohn noted, something else is written to the <secret> tag in ~/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml.

This manual step is however a bit of a downer when using automated deployment.

grav avatar Nov 23 '17 07:11 grav

@grav I am not sure how to move on with this. Do you know whats the difference is? I do not see any secret in the GhprbTrigger.

bjoernhaeuser avatar May 10 '18 15:05 bjoernhaeuser

Issue for me was that the $BUILD_URL variable returns null if the base URL of the jenkins instance is not explicitly configured (even though the correct URL was visible in the UI all the time).

For completeness sake, if you're looking to set this URL using Groovy scripts:

import jenkins.model.*

def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()
jenkinsLocationConfiguration.setUrl("https://www.your.jenkins.instance.com")

jenkinsLocationConfiguration.save()

eswets avatar Jun 07 '18 15:06 eswets

Same issue here, trying the fix above in the groovy script.

soundstep avatar Jun 30 '20 07:06 soundstep