Slack - Send Simple Notification - Bash

Octopus.Script exported 2020-03-02 by liam-mackie belongs to ‘Slack’ category.

Send a basic message notification to Slack.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Hook URL

ssn_HookUrl =

The Webhook URL provided by Slack, including token.

Channel handle

ssn_Channel =

Which Slack channel to post notification to.

Icon URL

ssn_IconUrl = https://octopus.com/content/resources/favicon.png

The icon shown in Slack against the notification.

Username

ssn_Username = Octopus Deploy

The username shown in Slack against the notification.

Title

ssn_Title =

The title of the notification in Slack.

Supported formatting includes: ```pre```, _italic_, *bold*, and even ~strike~.

Message

ssn_Message =

The body of the notification in Slack.

Supported formatting includes: ```pre```, _italic_, *bold*, and even ~strike~.

Color

ssn_Color = good

Like traffic signals, color-coding messages can quickly communicate intent and help separate them from the flow of other messages in the timeline.

Script body

Steps based on this template will execute the following Bash script.

# Define variables
channel=$(get_octopusvariable "ssn_Channel")
username=$(get_octopusvariable "ssn_Username")
icon_url=$(get_octopusvariable "ssn_IconUrl")
parse="full"
pretext=$(get_octopusvariable "ssn_Title")
text=$(get_octopusvariable "ssn_Message")
color=$(get_octopusvariable "ssn_Color")
webook_url=$(get_octopusvariable "ssn_HookUrl")

# Create JSON payload
json_payload='{"username": '
json_payload+="\"$username\""
json_payload+=', "parse": '
json_payload+="\"$parse\""
json_payload+=', "channel": '
json_payload+="\"$channel\""
json_payload+=', "icon_url": '
json_payload+="\"$icon_url\""
json_payload+=', "attachments" : [{"text": '
json_payload+="\"$text\""
json_payload+=', "color": '
json_payload+="\"$color\""
json_payload+=', "pretext": '
json_payload+="\"$pretext\""
json_payload+=', "mrkdwn_in": ["pretext","text"]}]}'

# Send webhook - redirect stderr to stdout
wget --post-data="$json_payload" --secure-protocol="auto" "$webook_url" 2>&1

# Check for error
if [[ $? -ne 0 ]]
then
    fail_step "Failed!"
fi

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "4ec2225e-9ffa-4072-9852-b986e8a98222",
  "Name": "Slack - Send Simple Notification - Bash",
  "Description": "Send a basic message notification to Slack.",
  "Version": 2,
  "ExportedAt": "2020-03-02T19:22:48.922Z",
  "ActionType": "Octopus.Script",
  "Author": "liam-mackie",
  "Packages": [],
  "Parameters": [
    {
      "Id": "0de9bf5f-302c-4b94-91eb-9e5fb0e37eb4",
      "Name": "ssn_HookUrl",
      "Label": "Hook URL",
      "HelpText": "The Webhook URL provided by Slack, including token.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "d55d5c10-9b82-43b1-8278-aedb72ba165f",
      "Name": "ssn_Channel",
      "Label": "Channel handle",
      "HelpText": "Which Slack channel to post notification to.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "e753bbfe-efc1-4d3b-a15d-036b5e8ae510",
      "Name": "ssn_IconUrl",
      "Label": "Icon URL",
      "HelpText": "The icon shown in Slack against the notification.",
      "DefaultValue": "https://octopus.com/content/resources/favicon.png",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "f25b4299-cfd0-4cb0-9c8c-48a706a01f02",
      "Name": "ssn_Username",
      "Label": "Username",
      "HelpText": "The username shown in Slack against the notification.",
      "DefaultValue": "Octopus Deploy",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "811722e7-c3d2-495f-822c-eb5a974407e3",
      "Name": "ssn_Title",
      "Label": "Title",
      "HelpText": "The title of the notification in Slack.\n\nSupported formatting includes: ` ```pre``` `, `_italic_`, `*bold*`, and even `~strike~`.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "b65a034b-d0b8-486b-a20a-2d105779a6db",
      "Name": "ssn_Message",
      "Label": "Message",
      "HelpText": "The body of the notification in Slack.\n\nSupported formatting includes: ` ```pre``` `, `_italic_`, `*bold*`, and even `~strike~`.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    },
    {
      "Id": "a9be62b0-a3a8-4940-baa4-47c6cd2f2312",
      "Name": "ssn_Color",
      "Label": "Color",
      "HelpText": "Like traffic signals, color-coding messages can quickly communicate intent and help separate them from the flow of other messages in the timeline.",
      "DefaultValue": "good",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "good|Green\nwarning|Orange\ndanger|Red"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "Bash",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "# Define variables\nchannel=$(get_octopusvariable \"ssn_Channel\")\nusername=$(get_octopusvariable \"ssn_Username\")\nicon_url=$(get_octopusvariable \"ssn_IconUrl\")\nparse=\"full\"\npretext=$(get_octopusvariable \"ssn_Title\")\ntext=$(get_octopusvariable \"ssn_Message\")\ncolor=$(get_octopusvariable \"ssn_Color\")\nwebook_url=$(get_octopusvariable \"ssn_HookUrl\")\n\n# Create JSON payload\njson_payload='{\"username\": '\njson_payload+=\"\\\"$username\\\"\"\njson_payload+=', \"parse\": '\njson_payload+=\"\\\"$parse\\\"\"\njson_payload+=', \"channel\": '\njson_payload+=\"\\\"$channel\\\"\"\njson_payload+=', \"icon_url\": '\njson_payload+=\"\\\"$icon_url\\\"\"\njson_payload+=', \"attachments\" : [{\"text\": '\njson_payload+=\"\\\"$text\\\"\"\njson_payload+=', \"color\": '\njson_payload+=\"\\\"$color\\\"\"\njson_payload+=', \"pretext\": '\njson_payload+=\"\\\"$pretext\\\"\"\njson_payload+=', \"mrkdwn_in\": [\"pretext\",\"text\"]}]}'\n\n# Send webhook - redirect stderr to stdout\nwget --post-data=\"$json_payload\" --secure-protocol=\"auto\" \"$webook_url\" 2>&1\n\n# Check for error\nif [[ $? -ne 0 ]]\nthen\n    fail_step \"Failed!\"\nfi"
  },
  "Category": "Slack",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/slack-send-simple-notification-bash.json",
  "Website": "/step-templates/4ec2225e-9ffa-4072-9852-b986e8a98222",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD9QTFRFW4cu56IU////TcCI4Q1jquLePyZDfNPcN5h70B4l6lOQz+7q8cl3g9Kw5/f2210d8Iax+ePS9rTOjRpToruuV87V3wAABolJREFUeNrsnY166iAMQLGV2VsKlm7v/6xX3dzUNin5gaofeYF5lgMNJFXTvEmYClJBKkgFqSAVpIJUkApSQSpIBakgFaSCVJA3AYnDsBuGIb42SBx2vzG8MMgNRiaUIiBxN4uXBFng0CcxG3Go22WKr49MJGajhJwivhgIxKGcErNZQpTXu9lohai7tSXI8FIgu10ZtzYFGSrIk4Hs3gYkvseupeoWAyRY609hgxxk7lZwzoZQAsT69hre6roV3OEaNmQGce19OCHIcENhD7dBRaGB2PYxrIpb4R7iO1w+EN/Ow4vdujHqPmwuENsuhZW5ZQ9wuDwgoV2OtT+HFPLGmAMWIQuIB0A8E8RcwqMkOUBc2zJTAlOcokVBXAYQD4J46r5lbgMFsRlAWjjWFhdMsepWUAcJCEi6W2YeSm4Z+RJJdsssR2EQ2/LdijDFmlu2LAj+fwvOYNE+EYjHKE4fp0VJyoJgawR061pGeRTEFwUJLdWt25KW7ZYr+UBccuuhpGW7pf8cwRfJvVtuVtJ6JkiOJ3uqW4uHJK5bOWqtJLccdLzoeCnJUsavuuWQQxLPrTznEXwDthYtNVhuZTohYvVv1+G1H2vfKnxmP1OcYwXkiwyS7xbFwRTrIFS3st5rwRTdulukfSvzTaMFKRJSkr5vWdfQgwTiQAg9t1gU5CtTmELqViei4Nz9dnDI9i1rQyMImlq26/gg+CKR9nwIF3TnRzcKwndLoXmVCHItaVtJSr5AC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Zn2VLc6jUG0WPQ5spCSbrUxmuZW2Sf7I0hH/E7KoeQDcWWR/LplOsVBtCy1VpPglukITfeUlJQ9j/yAmI410IGlJM9X7qByjV+SYSEgJYXP7N9llKUPdKyRZLzXGgEKxkDHOknWu9+He63bYlA0CbywTohvktBvGvslioY1LISgkF+IYd39jqeYl7RCt74Fu/xoV2S816P4BfhSt2ShCOIkbzA8E0jzNiBeMtL8TCDuXUDCu6iFuvVSIPY9tl9033KvBeI3M0sZJGyWEO3f6PEbrRD9Hxvy7Nr3yUCC34ZD/+efFkhKcOT4HStbfH1kAmluX0n2rnldkHP9+P2bXS40zWuDlI8KUkEqSAWpIBWkglSQClJBKkgFqSAVpIJUkKzxX4ABALbWvZucWNySAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Monday, March 2, 2020