Raygun API - Register Deployment

Octopus.Script exported 2024-04-09 by benjimac93 belongs to ‘Raygun’ category.

Notifies Raygun of a deployment using their Deployments API. Sends the release number, deployer, release notes from the Octopus deployment.

Parameters

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

Api Key

Raygun.ApiKey =

Raygun Application’s ApiKey (the same one you use to set Raygun up within your app)

Personal Access Token

Raygun.PersonalAccessToken =

Personal Access Token to use from your Raygun User Settings page.

Script body

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

Function Get-Parameter($Name, [switch]$Required, $Default, [switch]$FailOnValidate) {
    $result = $null
    $errMessage = [string]::Empty

    If ($OctopusParameters -ne $null) {
        $result = $OctopusParameters[$Name]
        Write-Host "Octopus paramter value for $Name : $result"
    }

    If ($result -eq $null) {
        $variable = Get-Variable $Name -EA SilentlyContinue
        if ($variable -ne $null) {
            $result = $variable.Value
        }
    }

    If ($result -eq $null) {
        If ($Required) {
            $errMessage = "Missing parameter value $Name"
        } Else {
            $result = $Default
        }
    } 

    If (-Not [string]::IsNullOrEmpty($errMessage)) {
        If ($FailOnValidate) {
            Throw $errMessage
        } Else {
            Write-Warning $errMessage
        }
    }

    return $result
}

& {
    Write-Host "Start AddInRaygun"

    $deploymentId = [string] (Get-Parameter "Octopus.Release.Number" $true [string]::Empty $true)
    $ownerName = [string] (Get-Parameter "Octopus.Deployment.CreatedBy.DisplayName" $true [string]::Empty $true)
    $emailAddress = [string] (Get-Parameter "Octopus.Deployment.CreatedBy.EmailAddress" $false [string]::Empty $true)
    $releaseNotes = [string] (Get-Parameter "Octopus.Release.Notes" $false [string]::Empty $true)
    $personAccessToken = [string] (Get-Parameter "Raygun.PersonalAccessToken" $true [string]::Empty $true)
    $apiKey = [string] (Get-Parameter "Raygun.ApiKey" $true [string]::Empty $true)
    $deployedAt = Get-Date -Format "o"

    Write-Host "Registering deployment with Raygun"

    # Some older API keys may contain URL reserved characters (eg '/', '=', '+') and will need to be encoded.
    # If your API key does not contain any reserved characters you can exclude the following line.
    $urlEncodedApiKey = [System.Uri]::EscapeDataString($apiKey);

    $url = "https://api.raygun.com/v3/applications/api-key/" + $urlEncodedApiKey + "/deployments"

    $headers = @{
        Authorization="Bearer " + $personAccessToken
    }

    $payload = @{
        version = $deploymentId
        ownerName = $ownerName
        emailAddress = $emailAddress
        comment = $releaseNotes
        deployedAt = $deployedAt
    }

    $payloadJson = $payload | ConvertTo-Json 


    try {
        Invoke-RestMethod -Uri $url -Body $payloadJson -Method Post -Headers $headers -ContentType "application/json" -AllowInsecureRedirect
        Write-Host "Deployment registered with Raygun"
    } catch {
        Write-Host "Tried to send a deployment to " $url " with payload " $payloadJson
        Write-Error "Error received when registering deployment with Raygun: $_"
    }

    Write-Host "End AddInRaygun"
}

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": "bb7de751-edba-4c5f-9845-1bd1b26f6b62",
  "Name": "Raygun API - Register Deployment",
  "Description": "Notifies [Raygun](https://raygun.com) of a deployment using their [Deployments API](https://raygun.com/documentation/product-guides/deployment-tracking/powershell/).\nSends the release number, deployer, release notes from the Octopus deployment.",
  "Version": 1,
  "ExportedAt": "2024-04-09T08:20:04.075Z",
  "ActionType": "Octopus.Script",
  "Author": "benjimac93",
  "Packages": [],
  "Parameters": [
    {
      "Id": "0dd429d3-28f6-46b8-8fb7-e2ceb9124c15",
      "Name": "Raygun.ApiKey",
      "Label": "Api Key",
      "HelpText": "Raygun Application's ApiKey (the same one you use to set Raygun up within your app)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "22d41dfb-f8f3-479d-8e72-08f456529f04",
      "Name": "Raygun.PersonalAccessToken",
      "Label": "Personal Access Token",
      "HelpText": "Personal Access Token to use from your [Raygun User Settings page](https://app.raygun.io/user).",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "Function Get-Parameter($Name, [switch]$Required, $Default, [switch]$FailOnValidate) {\n    $result = $null\n    $errMessage = [string]::Empty\n\n    If ($OctopusParameters -ne $null) {\n        $result = $OctopusParameters[$Name]\n        Write-Host \"Octopus paramter value for $Name : $result\"\n    }\n\n    If ($result -eq $null) {\n        $variable = Get-Variable $Name -EA SilentlyContinue\n        if ($variable -ne $null) {\n            $result = $variable.Value\n        }\n    }\n\n    If ($result -eq $null) {\n        If ($Required) {\n            $errMessage = \"Missing parameter value $Name\"\n        } Else {\n            $result = $Default\n        }\n    } \n\n    If (-Not [string]::IsNullOrEmpty($errMessage)) {\n        If ($FailOnValidate) {\n            Throw $errMessage\n        } Else {\n            Write-Warning $errMessage\n        }\n    }\n\n    return $result\n}\n\n& {\n    Write-Host \"Start AddInRaygun\"\n\n    $deploymentId = [string] (Get-Parameter \"Octopus.Release.Number\" $true [string]::Empty $true)\n    $ownerName = [string] (Get-Parameter \"Octopus.Deployment.CreatedBy.DisplayName\" $true [string]::Empty $true)\n    $emailAddress = [string] (Get-Parameter \"Octopus.Deployment.CreatedBy.EmailAddress\" $false [string]::Empty $true)\n    $releaseNotes = [string] (Get-Parameter \"Octopus.Release.Notes\" $false [string]::Empty $true)\n    $personAccessToken = [string] (Get-Parameter \"Raygun.PersonalAccessToken\" $true [string]::Empty $true)\n    $apiKey = [string] (Get-Parameter \"Raygun.ApiKey\" $true [string]::Empty $true)\n    $deployedAt = Get-Date -Format \"o\"\n\n    Write-Host \"Registering deployment with Raygun\"\n\n    # Some older API keys may contain URL reserved characters (eg '/', '=', '+') and will need to be encoded.\n    # If your API key does not contain any reserved characters you can exclude the following line.\n    $urlEncodedApiKey = [System.Uri]::EscapeDataString($apiKey);\n\n    $url = \"https://api.raygun.com/v3/applications/api-key/\" + $urlEncodedApiKey + \"/deployments\"\n\n    $headers = @{\n        Authorization=\"Bearer \" + $personAccessToken\n    }\n\n    $payload = @{\n        version = $deploymentId\n        ownerName = $ownerName\n        emailAddress = $emailAddress\n        comment = $releaseNotes\n        deployedAt = $deployedAt\n    }\n\n    $payloadJson = $payload | ConvertTo-Json \n\n\n    try {\n        Invoke-RestMethod -Uri $url -Body $payloadJson -Method Post -Headers $headers -ContentType \"application/json\" -AllowInsecureRedirect\n        Write-Host \"Deployment registered with Raygun\"\n    } catch {\n        Write-Host \"Tried to send a deployment to \" $url \" with payload \" $payloadJson\n        Write-Error \"Error received when registering deployment with Raygun: $_\"\n    }\n\n    Write-Host \"End AddInRaygun\"\n}"
  },
  "Category": "Raygun",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/raygun-api-register-deployment.json",
  "Website": "/step-templates/bb7de751-edba-4c5f-9845-1bd1b26f6b62",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD9QTFRF79YBphgc////nZ2cxMPD8Nwyxk81+Olz5eXl66ak+fGy+ebi0pII1iIg88vL/P38+Pbv1tXU4Ht1sLCwi4eHdrrVBAAAC7hJREFUeNrsnQmboyAMhj2pVhDE/v/fuoQz4NHLse0+oHPuzNS3XxICid2i+k9GkUEySAbJIBkkg2SQDJJBMkgGySAZJINkkAySQTJIBskgGSSDZJAMkkEySAbJIBkkg2SQDHJvcA4nfHSj0of5VH0/+jf+zSBw3fZahRBXcfVDfSEEN1Si+n4QuFRFcLm0bQGHHfBJq8ZFEQWxvhjEIuwOh3MiyVMgAHEHAY/LRcFUJ8E8AyKeofDKCO0q+jSfebs71IuKZ/R4lsMKY3ymQkGu+iwIvxYvjov3/0Bg4/ZHQPYkgXgVjygitNdh7PteutH34zCIAyV5CoRfNhzBXng8PA6llLDVQYjsx2NYngO5rjLsBONNhDCkMNPoqSCxbbVahW1ruw+hQSBBeJ/lmf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