This repository can be used as a Shared Library by Jenkins. It implements different steps to be used in a Jenkins Pipeline to send messages to Google Chat Service Groups.
- Add this repository to your Jenkins Global Pipeline Libraries as described here.
- Make sure that the HTTP Request Plugin is installed on your Jenkins. This library relies on it to send messages to Google Chat Service
- Use the library in your Jenkinsfile. Either check load implicitly or using a
@Library
annotation (see Using Libraries for details). - Configure a Webhook in your Google Chat Room and copy the URL.
- In your Jenkinsfile either set an environment variable and assign the URL to it.
If you name that variableGOOGLE_CHAT_URL
, it will be used automatically by the steps of this library, otherwise you will need to pass it as a parameter, which might be useful to send messages to different Groups.
Note that anyone knowing the URL will be able to send messages via your Webhook, so you should configure the URL as a secret text in your Jenkins' credentials section to keep it out of you version control and the Jenkins logs. See Using Credentials. - Use the steps as described below.
This step can be used to send Simple Messages. It takes the message as its only mandatory parameter. As a second parameter you can pass the Webhook URL or you can define it in an environment variable named GOOGLE_CHAT_URL
.
String message
(mandatory): The text message to be sent. You can use any formatting as described here.String url
(optional): the Google Chat Webhook URL to be used. Needs to be defined, ifenv.GOOGLE_CHAT_URL
is not set!``
sendGoogleChat("This is a _simple_ text message " +
"with a <https://github.com/mkutz/jenkins-google-chat-notification|link>" +
"\nand a line break, " +
"which might be interesting to <users/all> users in the Group.")
This step sends a bunch of data about the build as a Card Message.
Map<String, String> buildProperties
(optional): adds the given data as KeyValue Widgets to the Card Message. If there is a keymessage
it will be added as a Text Paragraph Widget instead.String url
(optional): the Google Chat Webhook URL to be used. Needs to be defined, ifenv.GOOGLE_CHAT_URL
is not set!``
sendGoogleChatBuildReport(Version: env.VERSION,
message: "This is a <strike>simple</strike> <i>card<i> text message " +
"with a <a href=\"https://github.com/mkutz/jenkins-google-chat-notification\">link</a>" +
"<br>and a line break, " +
"which does not support mention @all users in the Group.")