-
Bug
-
Resolution: Fixed
-
Major
-
None
-
Jenkins v2.2 on ArchLinux
-
Powered by SuggestiMate
I've setup my environment as described in this video: https://www.youtube.com/watch?v=uu5XcU4EPzQ
However, when build starts and finishes, I don't see the status on BitBucket commits. In Jenkins log I can see following messages:
May 13 10:57:18 rambo jenkins[743]: INFO: Bitbucket notify on start
May 13 10:57:19 rambo jenkins[743]: May 13, 2016 10:57:19 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
May 13 10:57:19 rambo jenkins[743]: INFO: This response was received:{"error": {"fields":
, "message": "Bad request"}}
May 13 10:57:19 rambo jenkins[743]: May 13, 2016 10:57:19 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier prebuild
May 13 10:57:19 rambo jenkins[743]: INFO: Bitbucket notify on start succeeded
Any idea what has been configured wrong?
Note: our Jenkins server is inside our local network and generally it is not available from public web. The exception is hole opened exclusively for BitBucket's IP ranges so that push notifications can be sent to Jenkins from BitBucket's webhooks.
[JENKINS-34788] Build status notification fails with "Enter a valid URL"
Hi Antonio. What is a "valid URL"?
I've tried setting following URLs as "Callback URL" of OAuth consumer, none of them worked:
http://141.138.8.191:54321/jenkins
http://141.138.8.191:54321
http://bitbucket:keyForBitbucketUserOnJenkinsServer@141.138.8.191:54321/jenkins (this one is used for notifying Jenkins that there was a push into a repository)
For security reason, 141.138.8.191:54321 is accessible only from these IP ranges: 131.103.20.160/27, 165.254.145.0/26 and 104.192.143.0/24 (as documented here: https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html)
In Manage Jenkins -> Jenkins Location -> Jenkins URL the set URL is: http://192.168.100.234/jenkins (this URL is accessible only from LAN - not from public Internet).
Hi dodoent, I was trying to reproduce your problem but I'm not able to reproduce it using the last plugin version. Which version of the plugin are you using actually the latest stable is 1.2.0? In case you are not using the latest stable one, could you please update the plugin and try again?
Thanks and regards.
Hi Antonio,
Jenkins plugin manager tells me that v1.2.0 is being used. I am keeping all my plugins up to date with the exception of "Bitbucket Pullrequest Builder Plugin" which I keep on 1.4.7 since every version after it causes infinite rebuilds of my pull requests (I've already issued the ticket to the author, yet it is still not fixed in 1.4.18).
Is there any debug log I can enable to help you find a problem? Can you add logging of the URL to which you are sending request? Currently only server response is logged. I would like to see the entire request and repeat it from commandline with curl - it may be possible that error is due to my firewall configuration.
Regards,
Nenad
Hi Nenad,
that's weird since it seems the communication with bitbucket is working, so the problem should not be caused by your firewall but in the plugin self. Try posting the build status manually from your terminal following this instructions:
First get the ACCESS_TOKEN:
curl -X POST https://bitbucket.org/site/oauth2/access_token -u "API_KEY:API_SECRET" -d grant_type=client_credentials
The response will be something like this:
{"access_token": "ACCESS_TOKEN", "scopes": "repository:write", "expires_in": 3600, "refresh_token": "sYf7Ka49Cc4kgFKFTV", "token_type": "bearer"}
Use the ACCESS_TOKEN received in the next request:
curl -X POST https://api.bitbucket.org/2.0/repositories/REPO_OWNER/REPO_NAME/commit/COMMIT_ID/statuses/build -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -d '{ "state": "SUCCESSFUL", "key": "BAMBOO-PROJECT-X-X", "name": "Build #34", "url": "https://example.com/path/to/build/info", "description": "Changes by John Doe"}'
I got to reproduce your problem and it seems that the attribute "url" is being set with a invalid URL value, so I guess it's a plugin internal problem. Before I deep in the plugin code, could you please confirm you get the previous example working?
Hi Antonio!
I can confirm that calling BitBucket with curl as you explained works correctly (I've tried issuing the request from both my laptop and server where Jenkins is installed).
When I put some random string which is not in URL form in field "url", then I get the same error as observed in jenkins log. Is there a way for me to enable logging which will show me what is the value plugin puts in "url" field before issuing a request?
Btw, one side question: how does plugin perform when I have option "merge before build" enabled in my Git plugin? I've tried issuing a curl request with merge commit created before build and Bitbucket responded with "Changeset not found.". Does in this case plugin send the commit ID of the original commit (before making a merge)?
Code changed in jenkins
User: Antonio Mansilla
Path:
src/main/java/org/jenkinsci/plugins/bitbucket/BitbucketBuildStatusNotifier.java
http://jenkins-ci.org/commit/bitbucket-build-status-notifier-plugin/35fb7cf5e7bf2638f38baadbd63a6885774b5a52
Log:
JENKINS-34788 Add more logging for easy debugging bitbucket request and response
Code changed in jenkins
User: Antonio Mansilla
Path:
src/main/java/org/jenkinsci/plugins/bitbucket/BitbucketBuildStatusNotifier.java
http://jenkins-ci.org/commit/bitbucket-build-status-notifier-plugin/acac5171f50f61ea098c49778868fdff12ec0ed8
Log:
Merge pull request #21 from Flagbit/issue-34651
JENKINS-34788 Add more logging for easy debugging bitbucket request
Hi dodoent, I've added right now the bitbucket request content to the log. It'll be released tomorrow or next friday, so wait until the new plugin version is available, update it and lets run the build to see what's going on.
Thank you a lot, amansilla. I am looking forward to being able to debug that issue.
I have been looking into a similar issues, where I was getting 'BAD REQUEST' responses from BitBucket.
In my case I was using the 'Multi-Branch Project' Plugin, which creates a folder, with a job per branch.
I traced the BAD REQUEST response back to the value of the "name" field in the build update request. This includes a '»' character from the call to getFullDisplayName in function createBitbucketBuildStatusFromBuild
String buildName = build.getProject().getFullDisplayName() + " #" + build.getNumber();
failing log:-
May 27, 2016 2:30:48 PM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
This request was sent: {
"state": "INPROGRESS",
"key": "d341c8de26d9cf205542b1e445ae0c53",
"url": "http://localhost:8080/job/Jenkins%20Test/branch/master/20/",
"name": "Jenkins Test » master #20"
}May 27, 2016 2:30:48 PM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
This response was received: Bad Request
changing to use getFullName (which uses a '/' char) fixed my issues.
String buildName = build.getProject().getFullName() + " #" + build.getNumber();
May 27, 2016 2:32:46 PM INFO org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
This request was sent: {
"state": "INPROGRESS",
"key": "b7fa1a78ad87d07cfe5413bbc34e0d84",
"url": "http://localhost:8080/job/Jenkins%20Test/branch/master/21/",
"name": "Jenkins Test/master #21"
}This response was received: {"name": "Jenkins Test/master #21", "links": {"commit":
Unknown macro: {"href"}, "self": {"href": "https://api.bitbucket.org/2.0/repositories/rivdevteam/jenkinstest/commit/7fce0b1f41e4f10cdd4faa7a62dd68a38e575e89/statuses/build/b7fa1a78ad87d07cfe5413bbc34e0d84"}}, "url": "http://localhost:8080/job/Jenkins%20Test/branch/master/21/", "created_on": "2016-05-27T13:32:41.883282+00:00", "repository": {"links": {"self":
Unknown macro: {"href"}, "html":
Unknown macro: {"href"}, "avatar": {"href": "https://bitbucket.org/rivdevteam/jenkinstest/avatar/32/"}}, "type": "repository", "name": "JenkinsTest", "full_name": "rivdevteam/jenkinstest", "uuid": "
Unknown macro: {faa4fbc3-155b-4de0-bedf-8a7338292d9d}"}, "state": "INPROGRESS", "key": "b7fa1a78ad87d07cfe5413bbc34e0d84", "updated_on": "2016-05-27T13:32:41.883319+00:00", "type": "build", "description": ""}
Hi flagbit,
I've finally received the update with logging enabled. Here are the logs of request and response:
Jun 06 09:29:38 rambo jenkins[747]: Jun 06, 2016 9:29:38 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
Jun 06 09:29:38 rambo jenkins[747]: INFO: This request was sent:
Jun 06 09:29:38 rambo jenkins[747]: Jun 06, 2016 9:29:38 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
Jun 06 09:29:38 rambo jenkins[747]: INFO: This response was received: {"error": {"fields":
, "message": "Bad request"}}
After cancelling the build:
Jun 06 09:30:02 rambo jenkins[747]: INFO: Bitbucket notify on finish
Jun 06 09:30:03 rambo jenkins[747]: Jun 06, 2016 9:30:03 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
Jun 06 09:30:03 rambo jenkins[747]: INFO: This request was sent:
Jun 06 09:30:03 rambo jenkins[747]: Jun 06, 2016 9:30:03 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier notifyBuildStatus
Jun 06 09:30:03 rambo jenkins[747]: INFO: This response was received: {"error": {"fields":
, "message": "Bad request"}}
Jun 06 09:30:03 rambo jenkins[747]: Jun 06, 2016 9:30:03 AM org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusNotifier perform
Jun 06 09:30:03 rambo jenkins[747]: INFO: Bitbucket notify on finish succeeded
Hopefully this can help debugging the issue.
Thank you for enabling the logging - I figured out the problem. The BitBucket API does not allow server names without dot. So while http://rambo/jenkins/job/AndroidCore/687/ was deemed as invalid URL, http://rambo.local/jenkins/job/AndroidCore/687/ was a valid URL.
After all it was not bug in plugin - it was a bug in configuration on my server.
Just a hint for future - if possible, please write somewhere (in documentation or setup guide) that server name should be a fully qualified name.
Hi dodoent, I've updated the plugin for validating the Jenkins Job URL before the build status is sent to Bitbucket API, that way we are be able to avoid bad requests and show a more suitable error message to the user.
Hi dodoent, there is some configuration checks missing in the video. Because of that I removed the video right now from the wiki page. Could you ensure you have a valid URL for the field Jenkins Location? Take a look here in the wiki page.