DEV Community

Brady Holt
Brady Holt

Posted on • Originally published at geekytidbits.com on

3 1

TIL: Post to Slack from Jenkins with curl

I recently needed to post to Slack from a Jenkins build but since the Slack Plugin for Jenkins doesn’t provide fine-grained configuration, I used a curl script in a post-build script.

First, I went created a new Jenkins CI configuration in Slack and noted the token it gave me ($SLACK_API_TOKEN below). Then, this is the curl script I used:

if ["$GIT_BRANCH" = "origin/master"]
then
curl -X POST -H "Content-Type: application/json" \
 -d '{"text":"'"$JOB_NAME"' - #'"$BUILD_NUMBER"' Failed on '"$GIT_BRANCH"' branch - '"$BUILD_URL"'"}' \
 "https://[domain].slack.com/services/hooks/jenkins-ci?token=$SLACK_API_TOKEN"
fi
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs