Last active
April 20, 2018 17:13
-
-
Save camsjams/0c66b59500588f28e8c0866d26d66915 to your computer and use it in GitHub Desktop.
CircleCI deploy message to slack [MIT]
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 | |
# Description: Call this from your CircleCi config after your deploys have been completed | |
# | |
# Set the following variables: | |
# ENVIRONMENT - the name of the environment the deploy went to, ex: "dev", "staging", "production" | |
# CHANNEL - the slack channel you want to post to | |
# WEBHOOK - the slack webhook url you created | |
# PACKAGE_VERSION - this defaults to looking in a package.json for the "version", customize to your liking and language | |
# PROJECT_NAME - this defaults to looking in a package.json for the "name", customize to your liking and language | |
ENVIRONMENT="test" | |
PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) | |
WEBHOOK="https://hooks.slack.com/services/[your webhook url]" | |
CHANNEL="#[your channel]" | |
BUILD_VERSION=$PACKAGE_VERSION-$CIRCLE_BUILD_NUM-$CIRCLE_SHA1 | |
PROJECT_NAME=$(sed -nE 's/^\s*"name": "(.*?)",$/\1/p' package.json) | |
MESSAGE="$CIRCLE_USERNAME deployed version \`$BUILD_VERSION\` of *$PROJECT_NAME* to $ENVIRONMENT" | |
curl -X POST --data-urlencode "payload={\"channel\": \"$CHANNEL\", \"username\": \"DeployBot\", \"text\": \"$MESSAGE\", \"icon_emoji\": \":rocket:\"}" $WEBHOOK | |
# The MIT License (MIT) | |
# Copyright 2018 Cameron Manavian | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment