tomasbjerre / pull-request-notifier-for-bitbucket

Bitbucket Server plugin that invokes a custom URL when a pull request event is triggered.
Other
185 stars 74 forks source link

NoHttpResponseException between prnfb and bitbucket-slack-notifier #310

Open mdecourcey opened 5 years ago

mdecourcey commented 5 years ago

We have been successfully using prnfb for many years to kick off builds in Jenkins, and those triggers continue to work.

I have followed the instructions on https://github.com/Igogrek/bitbucket-slack-notifier to integrate BitBucket with Slack using prnfb, bitbucket-slack-notifier and a custom bot in Slack. I have installed bitbucket-slack-notifier on the same server as bitbucket and verified that posting data to http://localhost:9999/notify or the ip address version of that successfully sends me a DM in Slack. But prnfb is getting a NoHttpResponseException in the logs whenever it tries POST to the same url. I've included the stack trace below, as well as configuration for both a jenkins button/notification that works and a slack button/notification that gets the exception.

I would appreciate any insight you might have. I'll continue to debug with my Operations team to see if we can figure this out from our side. The next thing I hope to try is putting b-s-n on a separate server, test that, and if that does not work give it a named domain that prnfb can call like it does with jenkins.rr.com.

tomasbjerre commented 5 years ago

What HTTP status code are you getting back when using curl?

Is the target system not being invoked? Or is it being invoked but still the plugin shows an exception?

mdecourcey commented 5 years ago

When using curl the HTTP status code is 200.

Using tcpdump I believe I have found the issue.

Short story: Content-type: application/json was not included as a header on the post when "Encode as JSON" was selected. Adding that as an "Optional HTTP headers to send with URL." fixed the issue and the notifications are now working.

Slightly longer story: Using tcpdump and recording the traffic to port 9999 on the server hosting bitbucket and the bitbucket-slack-notifier I was able to see the difference in packets between prnfb posting to b-s-n and curl/chrome posting to b-s-n. prnfb would not receive a response back AND it did not include all the same headers. It was missing Content-Type: application/json, Accept: application/json and Accept-Language: en-US, en. I found through trial and error that the only one of these needed to successfully call b-s-n was the Content-Type.

I'm not sure exactly what the intent behind "Encode as JSON" was, but my assumption was that it would add the Content-Type: application/json without adding anything to the optional headers. If that was the intent, then I believe this is a bug in prnfb. If it is not a bug, then I'll contact the maintainer of bitbucket-slack-notifier to update the integration instructions to include adding a the optional header.

tomasbjerre commented 5 years ago

Encoding as json just means variables will be encoded as json. So that they can safely be used in a post content json structure.

So not a bug!