PowerShell

Generate a Personal Access Token (PAT) for your build server to use from your Raygun User Settings page. The PAT will be required to have the deployments:write scope.


Add the following script to your deployment process:

[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True)]
    [string] $raygunPAT,
    [Parameter(Mandatory=$True)]
    [string] $raygunApiKey,
    [Parameter(Mandatory=$True)]
    [string] $version,
    [Parameter()]
    [string] $ownerName,
    [Parameter()]
    [string] $emailAddress,
    [Parameter()]
    [string] $scmIdentifier,
    [Parameter()]
    [string] $scmType,
    [Parameter()]
    [string] $releaseNotes,
    [Parameter()]
    [string] $deployedAt
)


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($raygunApiKey);

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

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

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


if($scmType -ne ""){
    $payload | Add-Member -NotePropertyName scmType -NotePropertyValue $scmType
}

$payloadJson = $payload | ConvertTo-Json 


try {
    Invoke-RestMethod -Uri $url -Body $payloadJson -Method Post -Headers $headers -ContentType "application/json"
    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: $_"
}

Call the script after a successful release.

-raygunPAT          Your Personal Access Token
-raygunApiKey       API key of the Raygun application to register the deployment for
-version            Version of your application you are deploying
-ownerName          Name of the user who created this deployment
-scmIdentifier      Identifier of the commit this release was built from
-scmType            Source control system you are using
-emailAddress       Email address of the user who created this deployment
-releaseNotes       Release notes for this deployment
-deployedAt         Time of the successful deployment (ISO-8601 formatted)