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.

--

--

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