Skip to content

Latest commit

 

History

History
132 lines (78 loc) · 5.01 KB

README.md

File metadata and controls

132 lines (78 loc) · 5.01 KB

Disclaimer

This project is a fork of the original work from https://github.com/sleroy/sonar-slack-notifier-plugin and https://github.com/bonespike/sonar-slack-notifier-plugin.

Together with @listemanuel95, we made modifications to have internationalization taking in count the changes introduced in the latest versions of SonarQube.

Starting from version 9.5 they separated the API from the core of Sonar, so it is now in a separate repository and they removed the i18n methods. We've tried to use org.sonar.api.utils.LocalizedMessages but the core.properties localization file is part of the core and is not accesible from plugins.

At last, we're sorry for repackaging the code under our own domain. We don't plant to merge it back to sleroy's nor bonespike's repos. Just appreciation words for the work they did.

Pre-requisites

Built with JDK 11.0.18 & Maven 3.8.7.

Works with

Tested with SonarQube 9.8 and sent messages to MatterMost 7.1.5 (current ESR) incoming webhooks.

Sonar Slack Notifier Plugin

SonarQube plugin for sending notifications to Slack

This plugin sends a Slack message of project analysis outcome to configured project specific slack channel. The plugin uses Incoming Web Hook as the integration mechanism with Slack and Slack-compatible API's.

Install

The plugin must be placed in SONAR_HOME/extensions/plugins directory and SonarQube must be restarted.

Using latest release

You can find the latest release from https://github.com/komodin/sonar-slack-notifier-plugin/releases/ page. Download the latest verion's jar file and drop in the directory mentioned above

Building from source

To build the plugin simply run:

mvn clean package

And it you will get the built .jar inside target directory.

Configuration (updates needed)

After the plugin has been installed, you need to configure it. Although SonarQube offers project level configurations for some plugins, they cannot be used with this plugin because it runs in the "server side", and only sees the global settings.

First of all, as administrator, go to Administration > Security > Users:

Click on Admin user tokens burger button:

Generate a new token with "No expiration" and copy it:

Go to Administration > Configuration > General Settings and you will see a new Slack category in the sidebar:

There are some mandatory fields that you have to fulfill:

  • Slack user alias
  • Plugin enabled
  • Default Slack channel
  • Server Token

In Server Token you have to paste the previously generated token and then click on Save button.

There's two ways to configure this plugin: in a generic way or in a per-project basis.

If you want to configure it in a generic way, you have to fulfill the Slack web integration hook:

And also the Default Slack channel:

And to configure it in a per-project basis, you have to configure the Project Hook URL, the Project Key (regex that will match the Project Key of the project) and the channel where you want to send the notifications:

Note: if you want to the notification to be sent either if the Quality Gate passed ok or if it failed, you have to click twice on the Send only if Quality Gate failed (note that by default is says "(not set)").

Wildcard support

The project key supports wildcards at the end. See kogitant#2

Example messages posted to Slack

New bug introduced

All good

Inspired by

Benefits from

SonarQube Plugin Development guides

Slack-compatible webhook integration and message formatting guides

Analyzing this project with unit test and integration test coverage

    mvn clean jacoco:prepare-agent install -DskipITs=true
    mvn jacoco:prepare-agent-integration failsafe:integration-test
    mvn sonar-maven-plugin:sonar -Dsonar.host.url=http://localhost:9000