amuniz / bitbucket-branch-source-plugin

5 stars 2 forks source link

POST /api/2.0/repositories/<org>/<repo>/<commit>/statuses/build fails when Jenkins url not configured #2

Open ctataryn opened 7 years ago

ctataryn commented 7 years ago

If you leave your Jenkins URL pointing at localhost under Manage Jenkins->Configure System->Jenkins Location->Jenkins URL when an api call is made by com.cloudbees.jenkins.plugins.bitbucket.client.BitBucketCloudApiAdapter for:

POST /api/2.0/repositories/<org>/<repo>/<commit>/statuses/build

It will fail with the error:

This response was received:{"error": {"fields": {"url": ["Enter a valid URL."]}, "message": "Bad request"}}

The reason for this is when you leave your Jenkins URL configured for localhost, somewhere along the way the URL is replaced with http://unconfigured-jenkins-location/... When this is passed into the POST body like so:

{"description":"The tests have started...","state":"INPROGRESS","url":"http://unconfigured-jenkins-location/job/myrepo/job/myjob/11/","key":"JENKINS-2","name":"#11"}

The BitBucket API will complain with the aforementioned error.

WORKAROUND: If you go in and just change the Jenkins URL, everything works right. Even if you change the Jenkins URL back to localhost it's enough just so that field is dirtied and then written to the configuration.

ljpeters commented 7 years ago

I've encountered a problem with 'unconfigured-jenkins-location' when trying to reach the jenkins build from bitbucket pull request. The URL pointed to http://unconfigured-jenkins-location/... , while the 'Jenkins location' in the jenkins configuration was supplied correctly.

Maybe because the bitbucket-branch-source-plugin was installed áfter the 'Jenkins location' was specified in the jenkins configuration, the URL was not set in the plugin configuration. After altering the jenkins location and then changing it back to the correct URL, the issue was resolved. Now bitbucket receives the correct url to jenkins for pull request builds. This imo confirms the workaround decribed above.

devpie commented 6 years ago

I also have this issue.