Octopus Deploy

Deployments in Raygun with Octopus Deploy

Registering Deployments with Octopus Deploy

Step 1

Generate an External Auth Token for your build server to use from your Raygun User Settings page

Step 2

Follow the instructions for setting up scripts to run directly on the Octopus Server. The rest of these instructions assume you chose to call your server role octopus-server.

Step 3

In Octopus, create a new "Run a PowerShell script" step in your deployment's Process. Give it a name, and choose the octopus-server role. This ensures your deployment is only registered once, instead of once per server your deployment runs on. Use the following powershell script in this step:

Write-Host "Adding deployment in Raygun"

$githubSha = ""
if ((Test-Path variable:\GithubToken) -And (Test-Path variable:\GithubRepo)) {
    try {
        $repo = "https://api.github.com/repos/" + $GithubRepo
        $tagName = "build-" + $OctopusParameters["Octopus.Action[DEPLOYMENT_STEP_NAME].Package.NuGetPackageVersion"]
        $githuburl = "$repo/git/refs/tags/"+ $tagName + "?access_token=" + $GithubToken
        $tagOutput = Invoke-RestMethod -Uri $githuburl
        $githubCommitUrl = $tagOutput.object.url + "?access_token=" + $GithubToken
        $output = Invoke-RestMethod -Uri $githubCommitUrl
        $githubSha = $output.object.sha
    }
   catch {
        Write-Host "Couldn't find Git tag"
   }
}

$deploymentId = $OctopusParameters['Octopus.Release.Number']
$ownerName = $OctopusParameters['Octopus.Deployment.CreatedBy.DisplayName']
$emailAddress = $OctopusParameters['Octopus.Deployment.CreatedBy.EmailAddress']
$comment = $OctopusParameters['Octopus.Release.Notes'];

$command = ConvertTo-Json @{
    apiKey = $RaygunApiKey
    version = $deploymentId
    ownerName = $ownerName
    emailAddress = $emailAddress
    comment = $comment
    scmIdentifier = $githubSha
}

$url = "https://app.raygun.io/deployments?authToken=" + $RaygunAuthToken
try {
    Invoke-RestMethod -Uri $url -Body $command -Method Post -ContentType "application/json"
    Write-Host "Added deployment in Raygun"
} catch {
    Write-Host "Error received when adding deployment in Raygun: " $_
}

You need to replace DEPLOYMENT_STEP_NAME with the name of the step in your process which deploys your Nuget package. If you don't use Github, you could just remove that whole section, or replace it with your own code to get your Git commit hash.

Step 4

Add the following Variables to your deployment: RaygunApiKeyRaygunAuthTokenGithubToken, and GithubRepo.

RaygunApiKey should be set your Raygun Application's ApiKey (the same one you use to set Raygun up within your app).

RaygunAuthToken should be set to the External Auth Token you generated in Step 1. You may want to set different RaygunApiKey values depending on the Environment being deployed to if you have separate Raygun Apps for your different Environments.

GithubToken should be set to a Personal Access Token from Github (generated here: https://github.com/settings/applications). The token just needs the repo scope.

GithubRepo should be the full name of your repo - somethink like MindscapeHQ/Raygun4Net.

Step 5

Deploy your application and watch the Deployments roll in!

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.