Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Integrate Stash with Slack using webhooks

This is a short article on how we integrate stash and slack in openmind

First of all i assume you have:

  • a working stash installation
  • a repository you to notify slack on pushes
  • stash user with administration priviledges
  • full access to the server (linux) where stash is installed on
  • a team configured on slack
  • slack user with administration priviledges

Prepare your stash server

Access your stash server and create a script

vim /home/appuser/

Paste the following:


echo "Notify commits to slack"

payload="payload={\"channel\":\"$channel\",\"username\":\"webhookbot\",\"text\":\"Push on ${STASH_REPO_NAME} by ${STASH_USER_NAME} <$STASH_USER_EMAIL>\",\"icon_emoji\":\"$icon\",\"attachments\":["
while read from_ref to_ref ref_name; do
  message=`git log --format=%B -n 1 ${to_ref}`
  title="[$STASH_REPO_NAME:$ref_name] <$3/commits/$to_ref|$to_ref>: $message"

curl -X POST --data-urlencode "$payload" $1

and save.

Make it executable

chmod +x /home/appuser/

Configure Slack

  1. Access to slack: (replace YOUR_TEAM with your team name)
  2. Select "Incoming WebHooks"
  3. Choose a channel from drop-down and click "Add incoming WebHook"
  4. You have a new webhook configured! Copy the URL under "Your Unique Webhook URL"

Configure Stash

  1. Access to stash web interface
  2. Go to your repository
  3. Click on Settings
  4. Click on Hooks
  5. Click on "Add Hook" button and then on "Search"
  6. Search for "External Hooks" and click "Install"
  7. Once installed, go back to Hooks page in your repository
  8. Click on "Enable" on the "External Post Receive Hook" row (not pre-receive)
  9. Put the full path to the executable script in "Executable" field: /home/appuser/
  10. Fill "Positional Parameters" with:
    • 1st line: Web hook url you copied at last point in previous paragraph
    • 2nd line: Channel name (#general)
    • 3rd line: full path to your web interface repository page (without trailing slash)
    • 4th line: emoji for your notification (🚀)

Everything should work! Try to push something!


Copy link

RCheesley commented Jun 9, 2014

May I suggest also explaining that when you copy the URL for the repo, to not include /browse :) Thank you so much, this works perfectly 👍

Copy link

phillpafford commented Dec 11, 2014

Could we get a condition to Pull Request and Merged? When the PR come in I get the Slack alert and it has the link to the Jira issue, when a Merge happens I get the same Slask alert but it has all zeros and no message. Example of both messages

-- Pull Request
Push on REPO by ppafford
[REPO:refs/heads/feature-PROJ-123] 6165ef95a52955f49596483f1f80f8a0f0b44f3d: PROJ-123: Generate some meaningful mock data

-- Merged
Push on REPO by ppafford
[REPO:refs/heads/feature-PROJ-123] 0000000000000000000000000000000000000000:

Copy link

perlsaiyan commented Feb 18, 2016

This only sends the last commit in a push, any way to include all commits from a push that has multiple changes?

Copy link

msouth commented Feb 10, 2017

@perlsaiyan I think that is what this gist is doing:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment