Slack - Send Simple Notification

Octopus.Script exported 2022-12-02 by twerthi 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 PowerShell script.

$payload = @{
    channel = $OctopusParameters['ssn_Channel']
    username = $OctopusParameters['ssn_Username'];
    icon_url = $OctopusParameters['ssn_IconUrl'];
    link_names = "true";
    attachments = @(
        @{
            mrkdwn_in = $('pretext', 'text');
            pretext = $OctopusParameters['ssn_Title'];
            text = $OctopusParameters['ssn_Message'];
            color = $OctopusParameters['ssn_Color'];
        }
    )
}

try {
	[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
    if ($PSVersionTable.PSVersion.Major -ge 6)
    {
        Invoke-Restmethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['ssn_HookUrl']
    }
    else
    {
        Invoke-Restmethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['ssn_HookUrl'] -UseBasicParsing
    }
} catch {
    Write-Host "An error occurred while attempting to send Slack notification"
    Write-Host $_.Exception
    Write-Host $_
    throw
}

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": "99e6f203-3061-4018-9e34-4a3a9c3c3179",
  "Name": "Slack - Send Simple Notification",
  "Description": "Send a basic message notification to Slack.",
  "Version": 15,
  "ExportedAt": "2022-12-02T23:43:25.720Z",
  "ActionType": "Octopus.Script",
  "Author": "twerthi",
  "Parameters": [
    {
      "Id": "1229c77a-d992-45c4-935a-47038be21ac1",
      "Name": "ssn_HookUrl",
      "Label": "Hook URL",
      "HelpText": "The Webhook URL provided by Slack, including token.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      },
      "Links": {}
    },
    {
      "Id": "1acaf080-aae7-4285-a055-e1148b46f9bb",
      "Name": "ssn_Channel",
      "Label": "Channel handle",
      "HelpText": "Which Slack channel to post notification to.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "05817770-0880-484f-880b-2e96b9793e09",
      "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"
      },
      "Links": {}
    },
    {
      "Id": "4ffb8455-28bb-4a97-b348-3b889e12c54a",
      "Name": "ssn_Username",
      "Label": "Username",
      "HelpText": "The username shown in Slack against the notification.",
      "DefaultValue": "Octopus Deploy",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "137004c7-8e31-45f4-a675-22cf3ccf3383",
      "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"
      },
      "Links": {}
    },
    {
      "Id": "34d06bf1-6407-498b-9877-9d4671511194",
      "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"
      },
      "Links": {}
    },
    {
      "Id": "13def0b7-bb5a-4b95-9538-8bba0201994a",
      "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"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "$payload = @{\n    channel = $OctopusParameters['ssn_Channel']\n    username = $OctopusParameters['ssn_Username'];\n    icon_url = $OctopusParameters['ssn_IconUrl'];\n    link_names = \"true\";\n    attachments = @(\n        @{\n            mrkdwn_in = $('pretext', 'text');\n            pretext = $OctopusParameters['ssn_Title'];\n            text = $OctopusParameters['ssn_Message'];\n            color = $OctopusParameters['ssn_Color'];\n        }\n    )\n}\n\ntry {\n\t[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12\n    if ($PSVersionTable.PSVersion.Major -ge 6)\n    {\n        Invoke-Restmethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['ssn_HookUrl']\n    }\n    else\n    {\n        Invoke-Restmethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['ssn_HookUrl'] -UseBasicParsing\n    }\n} catch {\n    Write-Host \"An error occurred while attempting to send Slack notification\"\n    Write-Host $_.Exception\n    Write-Host $_\n    throw\n}"
  },
  "Category": "Slack",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/slack-send-simple-notification.json",
  "Website": "/step-templates/99e6f203-3061-4018-9e34-4a3a9c3c3179",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD9QTFRFW4cu56IU////TcCI4Q1jquLePyZDfNPcN5h70B4l6lOQz+7q8cl3g9Kw5/f2210d8Iax+ePS9rTOjRpToruuV87V3wAABolJREFUeNrsnY166iAMQLGV2VsKlm7v/6xX3dzUNin5gaofeYF5lgMNJFXTvEmYClJBKkgFqSAVpIJUkApSQSpIBakgFaSCVJA3AYnDsBuGIb42SBx2vzG8MMgNRiaUIiBxN4uXBFng0CcxG3Go22WKr49MJGajhJwivhgIxKGcErNZQpTXu9lohai7tSXI8FIgu10ZtzYFGSrIk4Hs3gYkvseupeoWAyRY609hgxxk7lZwzoZQAsT69hre6roV3OEaNmQGce19OCHIcENhD7dBRaGB2PYxrIpb4R7iO1w+EN/Ow4vdujHqPmwuENsuhZW5ZQ9wuDwgoV2OtT+HFPLGmAMWIQuIB0A8E8RcwqMkOUBc2zJTAlOcokVBXAYQD4J46r5lbgMFsRlAWjjWFhdMsepWUAcJCEi6W2YeSm4Z+RJJdsssR2EQ2/LdijDFmlu2LAj+fwvOYNE+EYjHKE4fp0VJyoJgawR061pGeRTEFwUJLdWt25KW7ZYr+UBccuuhpGW7pf8cwRfJvVtuVtJ6JkiOJ3uqW4uHJK5bOWqtJLccdLzoeCnJUsavuuWQQxLPrTznEXwDthYtNVhuZTohYvVv1+G1H2vfKnxmP1OcYwXkiwyS7xbFwRTrIFS3st5rwRTdulukfSvzTaMFKRJSkr5vWdfQgwTiQAg9t1gU5CtTmELqViei4Nz9dnDI9i1rQyMImlq26/gg+CKR9nwIF3TnRzcKwndLoXmVCHItaVtJSr5ACoXGqEnNxfW/KgA5gBAK/URDoRC65TuQIjfI/JDUai137aY7CrJUmau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/LplOsVBtCy1VpPglukITfeUlJQ9j/yAmI410IGlJM9X7qByjV+SYSEgJYXP7N9llKUPdKyRZLzXGgEKxkDHOknWu9+He63bYlA0CbywTohvktBvGvslioY1LISgkF+IYd39jqeYl7RCt74Fu/xoV2S816P4BfhSt2ShCOIkbzA8E0jzNiBeMtL8TCDuXUDCu6iFuvVSIPY9tl9033KvBeI3M0sZJGyWEO3f6PEbrRD9Hxvy7Nr3yUCC34ZD/+efFkhKcOT4HStbfH1kAmluX0n2rnldkHP9+P2bXS40zWuDlI8KUkEqSAWpIBWkglSQClJBKkgFqSAVpIJUkKzxX4ABALbWvZucWNySAAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Friday, December 2, 2022