HipChat - Notify

Octopus.Script exported 2014-07-29 by stephengodbold belongs to ‘HipChat’ category.

Notifies a HipChat room of a deployment outcome.

Parameters

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

API Auth Token

AuthToken

HipChat authentication token for a user who can post notifications to rooms

Room

RoomId

The room name that you wish to post a notification to

Notification Text

NotificationText

An optional text override for the notification. Default is: <(succeeded) or (failed)> (Project) v(Release) deployed to (Environment) on (Machine)

Notification Color

NotificationColor

The color for the notification for the room. Default messages will receive green success, and red failure.

Script body

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

#--------- Notify-Hipchat
$apitoken = $OctopusParameters['AuthToken']
$roomid = $OctopusParameters['RoomId']
$messageText = "(successful)"
$color = 'green'

if ($OctopusParameters['Octopus.Deployment.Error']) {
    $messageText = "(failed)"
    $color = 'red'
}

$messageValue = "$messageText $($OctopusParameters['Octopus.Project.Name']) [v$($OctopusParameters['Octopus.Release.Number'])] deployed to $($OctopusParameters['Octopus.Environment.Name'])    on $($OctopusParameters['Octopus.Machine.Name'])"

if ($OctopusParameters['NotificationText']) {
    $messageValue = $OctopusParameters['NotificationText']
    $color = $OctopusParameters['NotificationColor']
}

$message = New-Object PSObject 
$message | Add-Member -MemberType NoteProperty -Name color -Value $color
$message | Add-Member -MemberType NoteProperty -Name message -Value $messageValue
$message | Add-Member -MemberType NoteProperty -Name notify -Value $false
$message | Add-Member -MemberType NoteProperty -Name message_format -Value text

#Do the HTTP POST to HipChat
$uri = "https://api.hipchat.com/v2/room/$roomid/notification?auth_token=$apitoken"
$postBody = ConvertTo-Json -InputObject $message
$postStr = [System.Text.Encoding]::UTF8.GetBytes($postBody)

$webRequest = [System.Net.WebRequest]::Create($uri)
$webRequest.ContentType = "application/json"
$webrequest.ContentLength = $postStr.Length
$webRequest.Method = "POST"

$requestStream = $webRequest.GetRequestStream()
$requestStream.Write($postStr, 0,$postStr.length)
$requestStream.Close()

[System.Net.WebResponse] $resp = $webRequest.GetResponse()
$rs = $resp.GetResponseStream()

[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs
$sr.ReadToEnd()

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": "6a6ce997-c91b-4e06-b237-4484417efc89",
  "Name": "HipChat - Notify",
  "Description": "Notifies a HipChat room of a deployment outcome.",
  "Version": 0,
  "ExportedAt": "2014-07-29T01:56:04.693+00:00",
  "ActionType": "Octopus.Script",
  "Author": "stephengodbold",
  "Parameters": [
    {
      "Name": "AuthToken",
      "Label": "API Auth Token",
      "HelpText": "HipChat authentication token for a user who can post notifications to rooms",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "RoomId",
      "Label": "Room",
      "HelpText": "The room name that you wish to post a notification to",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NotificationText",
      "Label": "Notification Text",
      "HelpText": "An optional text override for the notification. Default is: <(succeeded) or (failed)> (Project) v(Release) deployed to (Environment) on (Machine)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "NotificationColor",
      "Label": "Notification Color",
      "HelpText": "The color for the notification for the room. Default messages will receive green success, and red failure.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "#--------- Notify-Hipchat\n$apitoken = $OctopusParameters['AuthToken']\n$roomid = $OctopusParameters['RoomId']\n$messageText = \"(successful)\"\n$color = 'green'\n\nif ($OctopusParameters['Octopus.Deployment.Error']) {\n    $messageText = \"(failed)\"\n    $color = 'red'\n}\n\n$messageValue = \"$messageText $($OctopusParameters['Octopus.Project.Name']) [v$($OctopusParameters['Octopus.Release.Number'])] deployed to $($OctopusParameters['Octopus.Environment.Name'])    on $($OctopusParameters['Octopus.Machine.Name'])\"\n\nif ($OctopusParameters['NotificationText']) {\n    $messageValue = $OctopusParameters['NotificationText']\n    $color = $OctopusParameters['NotificationColor']\n}\n\n$message = New-Object PSObject \n$message | Add-Member -MemberType NoteProperty -Name color -Value $color\n$message | Add-Member -MemberType NoteProperty -Name message -Value $messageValue\n$message | Add-Member -MemberType NoteProperty -Name notify -Value $false\n$message | Add-Member -MemberType NoteProperty -Name message_format -Value text\n\n#Do the HTTP POST to HipChat\n$uri = \"https://api.hipchat.com/v2/room/$roomid/notification?auth_token=$apitoken\"\n$postBody = ConvertTo-Json -InputObject $message\n$postStr = [System.Text.Encoding]::UTF8.GetBytes($postBody)\n\n$webRequest = [System.Net.WebRequest]::Create($uri)\n$webRequest.ContentType = \"application/json\"\n$webrequest.ContentLength = $postStr.Length\n$webRequest.Method = \"POST\"\n\n$requestStream = $webRequest.GetRequestStream()\n$requestStream.Write($postStr, 0,$postStr.length)\n$requestStream.Close()\n\n[System.Net.WebResponse] $resp = $webRequest.GetResponse()\n$rs = $resp.GetResponseStream()\n\n[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs\n$sr.ReadToEnd()",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "HipChat",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/hipchat-notify.json",
  "Website": "/step-templates/6a6ce997-c91b-4e06-b237-4484417efc89",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////HVCAvMvZaourDJE3ngAABCpJREFUeNrsXe12KyEI3DDv/85N2rT52igrg2DK3D/tPafqCCIqsNtWKBQKhUKhUCgUCoVCoVAoFAoFZ4gILjj94fvX838vxOF++Hs488kvhw6HOzZ5ZaMncSPzCSwychllkYyLicWVy+rCSCMWFo1gKkwagVTYNKKoONCIWPZycsNUoZw8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