Brady Holt
Posted on • Originally published atgeekytidbits.com on
TIL: Post to Slack from Jenkins with curl
I recently needed to post to Slack from a Jenkins build but since theSlack Plugin for Jenkins doesn’t provide fine-grained configuration, I used a curl script in a post-build script.
First, I went created a newJenkins 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"]thencurl -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
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse