Last active
April 23, 2018 13:33
-
-
Save jacoor/65855b4e4a5bf18018abaa90ae077f58 to your computer and use it in GitHub Desktop.
Publishing to slack #channel as jenkins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
to set up auth token first authorize jenkins as an slack app and install | |
https://wiki.jenkins.io/display/JENKINS/Slack+Plugin | |
Afterwards, use https://plugins.jenkins.io/credentials-binding, which is most likely available in your jenkins install | |
and use the instructions from there to share credentials with job. Accessing credentials in python requires: os.environ['xxx'] | |
""" | |
import os | |
import requests | |
import json | |
requests.post(' https://domain.slack.com/services/hooks/jenkins-ci/'+os.environ["slack-auth-token"], data =json.dumps({"channel": "portal","text":"my message"})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
# send notification about commits pushed to $1 branch | |
#!/bin/bash -ex | |
message="Following commits were just pushed to $1 branch:" | |
changelog=$(git log ${GIT_PREVIOUS_SUCCESSFUL_COMMIT}..HEAD) | |
fullmessage="$message $changelog" | |
curl -X POST -H "Content-type: application/json" \ | |
https://fraudnet.slack.com/services/hooks/jenkins-ci/${SLACK_AUTH_TOKEN} \ | |
--data-binary @- << EOF | |
{ | |
"channel": "portal", | |
"text": " ${fullmessage//\"/$q_mid}" | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If other ways of sending messages to slack are required, check their documentation for incoming webhooks. This allows to send basically any info to slack as "webhook".