Create deployments from Azure DevOps Pipelines

Notifying elmah.io about new deployments is possible as a build step in Azure DevOps, by adding a bit of PowerShell.

Using YAML

  1. Edit your build definition YAML file.

  2. If not already shown, open the assistant by clicking the Show assistant button.

  3. Search for 'powershell'.

  4. Click the PowerShell task.

  5. Select the Inline radio button and input the following script:

$ProgressPreference = "SilentlyContinue"

$url = "https://api.elmah.io/v3/deployments?api_key=API_KEY"
$body = @{
  version = "$env:BUILD_BUILDNUMBER"
  description = "$env:BUILD_SOURCEVERSIONMESSAGE"
  userName = "$env:BUILD_REQUESTEDFOR"
  userEmail = "$env:BUILD_REQUESTEDFOREMAIL"
  logId = "LOG_ID"
}
[Net.ServicePointManager]::SecurityProtocol = `
    [Net.SecurityProtocolType]::Tls12,
    [Net.SecurityProtocolType]::Tls11,
    [Net.SecurityProtocolType]::Tls
Invoke-RestMethod -Method Post -Uri $url -Body $body

Replace API_KEY with your API key (Where is my API key?) and LOG_ID (Where is my log ID?) with the id of the log representing the application deployed by this build configuration.

Click the Add button and the new task will be added to your YAML definition. You typically want to move the deployment task to the last placement in tasks.

Using Classic editor

  1. Edit the build definition currently building your project(s).

  2. Click the Add task button and locate the PowerShell task. Click Add. Add PowerShell task

  3. Fill in the details as shown in the screenshot. Fill in PowerShell content

... and here's the code from the screenshot above:

$ProgressPreference = "SilentlyContinue"

$url = "https://api.elmah.io/v3/deployments?api_key=API_KEY"
$body = @{
  version = "$env:BUILD_BUILDNUMBER"
  description = "$env:BUILD_SOURCEVERSIONMESSAGE"
  userName = "$env:BUILD_REQUESTEDFOR"
  userEmail = "$env:BUILD_REQUESTEDFOREMAIL"
  logId = "LOG_ID"
}
[Net.ServicePointManager]::SecurityProtocol = `
    [Net.SecurityProtocolType]::Tls12,
    [Net.SecurityProtocolType]::Tls11,
    [Net.SecurityProtocolType]::Tls
Invoke-RestMethod -Method Post -Uri $url -Body $body

Replace API_KEY with your API key (Where is my API key?) and LOG_ID (Where is my log ID?) with the id of the log representing the application deployed by this build configuration.


This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.

See how we can help you monitor your website for crashes Monitor your website