How to Integrate Google Chat With Jenkins Using Webhook? — Devstringx

Devstringx Technologies
4 min readAug 24, 2023

--

Integration of Google Chat with Jenkins

In one of our projects, we moved to use Google Chat as a communication platform so the need arose for having the pipeline notifications in Google Chat (all our pipelines are setup in Jenkins), we started the work and found that not much help is available online for this as compared to other platforms like Slack or teams so we thought of writing this blog which might be helpful for others who are looking to perform such integration.

Short Intro of Tools

Some of the short tools that help to integrate Google Chat with Jenkins:-

  • Google Chat

Google Chat is a messaging and collaboration platform that allows teams to communicate in real time, share information, and collaborate on projects.

  • Jenkins

Jenkins is an open-source continuous integration/continuous delivery and deployment (CI/CD) automation software/DevOps tool.

Benefits to Integrate Google Chat with Jenkins

It provides several benefits to our development and operations workflow, some of the benefits are mentioned below:

  • Reduced Email clutter
  • Google Chat is also accessible in mobile apps, so by this, team members stay updated on Jenkins notifications even when they are not at their desks
  • Real-Time Notification etc

Steps to Integrate Google Chat with Jenkins

To integrate Google with Jenkins we have to do the configuration of Google Chat and Jenkins Job.

Google Chat Configuration

  • Open the Google Chat space to configure the webhook, If no Google Chat space exists, then create a new Space, please see the below image for reference.
  • Access the Webhook setting by clicking on the space name at the top and selecting the Apps & Integration option, Please see the below image for reference.
  • Check from a list of existing webhooks if any, otherwise, create a new webhook by clicking the Manage webhooks button as shown in the below image.
  • Fill in all information such as name, icon, and other configuration options, and click Save to create an incoming webhook.
  • Once the webhook is created or selected, you can copy the webhook URL and use it for Jenkins integration.

Good to Read:- How to Setup Jenkins and Integrate NUnit Selenium C#?

Jenkins Job Configuration

Note: Please make sure you have the rights to do the configurations, for this article we are using a local installation of Jenkins.

  • Once you are logged in with your user then click on New Item from Jenkins Dashboard
  • Enter Project Name into the “Item Name” input field and select Project type “Pipeline”
  • Add Pipeline Script and mention Google Chat webhook into your pipeline script and Save the Job.

Code Snippet

pipeline {

agent any

stages {

// Define your pipeline stages here

}

post {

always {

script {

def googleChatWebhook = ‘YOUR_WEBHOOK_URL_HERE’

def jobName = env.JOB_NAME

def buildUrl = env.BUILD_URL

def message = “Pipeline job ‘${jobName}’ (${buildUrl}) has started.”

sh “””

curl -X POST -H ‘Content-Type: application/json’ -d ‘{

“text”: “${message}”

}’ ${googleChatWebhook}

“””

}

}

}

}

  • Click the Build Now option to run the job
  • You will get the notification on your Google chat Space.

Note: You can Customize the notification message in normal text format or in Card format.

Conclusion

Overall, integrating Google Chat with Jenkins streamlines communication improves collaboration, and helps teams stay informed about the status of their CI/CD pipeline and software development process. It’s a way to bring relevant information directly to the place where your team is already communicating and collaborating.

Originally published at https://www.devstringx.com on Aug 24, 2023

--

--

Devstringx Technologies
Devstringx Technologies

Written by Devstringx Technologies

Devstringx Technologies is highly recommended IT company for custom software development, mobile app development and automation testing services

No responses yet