Integrate SonarQube webhook with Discord

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 7.1

  • what are you trying to achieve
    I want to integrate discord webhook in sonarqube. So that i can get notified on my discord chennel
    when code analysis completed.

  • what have you tried so far to achieve this
    I am using discord application in my organisation and i am using multiple discord webhook to get notified for different applications.

I have tried to configure webhook for discord but it’s getting 400 code when code analyse completed and not sending notification to my discord chennel.

example hook my discord : https://discordapp.com/api/webhooks/58534458/vh-C-8xihQkQ8ykrJ9j6ZlymtbFil


sonar-webhook1

Hi,

400 is a “Bad Request”. Are you sure you’ve configured the SQ webhook with the correct URL?

 
Ann

1 Like

yes URL is correct because i am using multiple webhooks for my apps. i am receiving notification by same webhook from different app, but not working with sonarqube.

i have created webhook from my discord app and added it in sonarqube > administrator > webhook.

@ganncamp Is there any solution on this ? Does sonarqube supports discord webhooks ?

Steps i tried :

  1. Created webhook URL from my discord chennel.
  2. Configured that webhook URL in sonarqube > Administration > Configuration > Webhooks .
  3. Run code scan So that it send notification to configured webhook.

But i am getting below error.

Error :

Last delivery of Spidey Bot

Response: 400
Duration: 186ms
Payload: .....

Discord Webhook image :slight_smile:

SonarQube webhook error. :face_with_raised_eyebrow:

Hi,

Our webhooks invoke the URL you configure after background task processing is complete. Does that mean we support / don’t support Discord? I have no idea. I don’t know what Discord’s requirements are. Is it expecting a GET? Then probably not. I think we use POST. Beyond that, all I can really say is that your Discord server returned an error code, which implies it didn’t get what it was looking for.

Sorry I can’t be more helpful.

 
Ann

There is a stackoverflow question of this issue: the link to the stackoverflow question

The answer is:
It turns out, request body format which SonarQube sends to Discord is not acceptable. It leads to bad request error. Below is logged response from Discord,

{ “message”: “Cannot send an empty message”, “code”: 50006 }

To successfully post the message it must be in the specific format documented https://discordapp.com/developers/docs/resources/webhook#execute-webhook

The solution to this could be a mediatory URL which parses the request body and hits Discord Webhook with excepted body params.