mardi 27 février 2018

Sending a notification on task failure in Gradle

Our team is using Bamboo to provide continuous integration and delivery of Grails/Gradle applications. We wanted to have notifications on build failure for the 'test' tasks but realized that there is no connector for Bamboo for Microsoft teams (We tried one unofficial one and couldn't make it work).

As a workaround, I created a new task in gradle that would run on task failure if the -Pci=true argument is given to the command line. In case of build failure the task will send a message to Microsoft teams through the REST API.

Here is the code for that kind of tasks:

The isCi check is done to avoid sending notifications when the tasks are run in development environments.