Maven build stage status from Jenkins to Slack

Notify Slack about build stage status from a Maven Job from Jenkins. Assuming Slack incoming webhooks and few secret bindings in Jenkins are already done.
This seems to work only with Maven jobs.

set +x build_status=$(curl -su "$jenkins_login" "$BUILD_URL"/api/xml | grep result | sed 's/^.*<result>//' | sed 's/<\/result>.*$//') curl -X POST --data-urlencode "payload={\"channel\": \"#general\", \"username\": \"Jenkins\", \"text\": \"$JOB_BASE_NAME build - $BUILD_DISPLAY_NAME\nBuild status = "$build_status"\", \"icon_emoji\": \":jenkins:\"}" https://hooks.slack.com/services/$SLACK_TOKEN

Above script is entered into Post Steps of a Maven job.
Jenkins credentials and Slack webhook is stored as secrets.
Status of the build retrieved from Jenkins API and is stored in build_status. It is then used in curl to notify Slack.

--

--

--

I work with cloud, containers, linux

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Drawing a heart in Python

GIT and GITHUB Training Course

How to build a very simple CLI program to make HTTP requests with Go

Computer Storage Devices

Real Advantage of Automating Testing on Apps: Benefits of Automation Testing?

Azure — Difference between Azure Load Balancer and Application Gateway

Introducing real-time Open-Source Indexes: Databases, Headless CMSs and Static Site Generators

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adithya

Adithya

I work with cloud, containers, linux

More from Medium

Docker and The Rise of Containerization

Docker Multi-Stage builds

Let’s change configuration of Fluent Bit in Docker