Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Latest commit

 

History

History
125 lines (93 loc) · 5.61 KB

README.md

File metadata and controls

125 lines (93 loc) · 5.61 KB

Go GChat Notifier Plugin

Java CI Integration Test Code coverage GitHub release (latest SemVer) ReleaseDate License

This repo has been set to read-only because we are no longer using GoCD and couldn't find another maintainer in our organization to maintain the project. Feel free to fork.

A GoCD notification plugin for the GoCD continuous integration server.

Chat messages are defined by a template and can look like this:


GChat screenshot


The plugin is very customizable by using the template language Apache Freemarker as an approach to formulate

  • the condition when to send messages, and
  • the chat message body themselves.

Requirements

The go-gchat-notifier-plugin requires at least the following environment:

  • Google Workspace account so you can create GChat webhooks
  • GoCD 18.9.0 and later
  • JDK 8 and later (the JDK GoCD is running with)

Installation

Download go-gchat-notifier-plugin.jar into the plugins/external directory of your GoCD server and restart it.

You can also download a signed jar from the maven repository and verify the GPG signature with my GPG public key.

Getting a GChat webhook URL

At the moment the plugin works only with GChat webhook URLs. Webhook URLs can as far as I know only be generated by Google Workspace customers, not individuals.

To generate a GChat webhook URL

  • go to an existing space in GChat,
  • go the space menu right besides the space name,
  • click 'Apps & integrations' menu,
  • click 'Manage webhooks',
  • add a new webhook name, provide an optional avatar URL and press 'Save'.
  • a webhook URL will be generated for you.

At the moment, the webhook URLs look like this:

https://chat.googleapis.com/v1/spaces/.../messages?key=...&token=...

See also Google Workspace documentation.

Configuration

The following is a screenshot of the configuration dialogue of version 0.5.0:

Plugin Config screenshot

The following configuration items exist in the plugin:

  • GChat template (freemarker):* A freemarker format template for the chat message body. The template has access to the following objects that are registered in the template's context:
    • stageStatus: The original stage status request from the GoCD server. Can be used to render some information about the pipeline. See this json or this image for a sample on the document structure.
    • serverInfo: The server info object that contains the server's address(es). Can be used to render some URLs towards the console. See this json or this image for a sample on the document structure.
  • Condition for sending (freemarker):* A freemarker format template that either needs to render to the String true or false to decide whether to send a message (true) or not (false). Gets the same objects as the template above.
  • GChat webhook URL:* The mandatory GChat space webhook URL to send messages to. Please see 'Getting a GChat webhook URL' on how to get a webhook.
  • Optional proxy URL: An optional HTTP proxy URL to use for sending traffic to GChat. At the moment only the URL can be provided, there is no separate way for configuring user/password authentication.

Sample Configuration

In the following is a usable sample for a configuration. The configuration only notifies on stage states which are in state Failed and sends a chat message that has a direct deep link into your GoCD instances console of the stage run.

GChat template (freemarker)

*Failed:* ${stageStatus.pipeline.group}/${stageStatus.pipeline.name}/${stageStatus.pipeline.stage.name} is ${stageStatus.pipeline.stage.state}, result ${stageStatus.pipeline.stage.result}
<#list stageStatus.pipeline.stage.jobs as job>
${job.name}: ${job.result} <#if serverInfo['secure_site_url']??><${serverInfo.secure_site_url}/go/tab/build/detail/${stageStatus.pipeline.name}/${stageStatus.pipeline.counter}/${stageStatus.pipeline.stage.name}/${stageStatus.pipeline.stage.counter}/${job.name}|console></#if>
</#list>

Condition for sending (freemarker)

${(stageStatus.pipeline.stage.state == 'Failed')?string('true', 'false')}