Skip to main content
Back to blog

Service Hooks in Azure DevOps for Test Automation

How to use Azure DevOps Service Hooks to trigger test automation, send notifications, and integrate with external tools. Covers webhook configuration, build completion hooks, Teams/Slack notifications, and custom event handlers.

InnovateBits4 min read
Share

Service Hooks let Azure DevOps send events to external systems when something happens — a build completes, a test run finishes, a bug is created. For QA teams, this enables automated notifications, external system triggers, and event-driven workflows.


What Service Hooks can trigger on

EventQA relevance
Build completedTest run finished — notify QA team
Release completedDeployment done — start post-deploy tests
Work item createdNew bug — notify responsible developer
Work item state changedBug resolved — prompt QA to verify
Pull request createdTrigger external code review tool

Setting up Service Hooks

  1. Go to Project Settings → Service hooks → + Create subscription
  2. Select the service: Teams, Slack, WebHooks, etc.
  3. Select the event trigger
  4. Configure filters (e.g., only trigger when pipeline fails)
  5. Configure the target (webhook URL, channel, etc.)

Microsoft Teams notifications

The most common QA use case: notify the team when the regression pipeline fails.

  1. In Teams, create an Incoming Webhook for your QA channel:

    • Channel → More options → Connectors → Incoming Webhook → Add
    • Copy the webhook URL
  2. In Azure DevOps: Service Hooks → New → Microsoft Teams

  3. Event: Build completed

  4. Filters:

    • Pipeline: Nightly Regression
    • Status: Failed
  5. Action: post the webhook URL

The notification includes: build number, failed stage, and a direct link to the test results.


Slack notifications

Similar to Teams. Generate a Slack Incoming Webhook from your workspace:

  1. Service Hooks → New → Slack
  2. Event: Build completed
  3. Webhook URL: your Slack channel webhook

Customise the message format using Slack's Block Kit in the webhook payload.


Custom webhooks for test automation triggers

Trigger a test run on an external system when a deployment completes:

// Webhook payload sent by Azure DevOps when release completes
{
  "eventType": "ms.vss-release.release-deployment-completed-event",
  "resource": {
    "environment": {
      "name": "Staging"
    },
    "release": {
      "name": "Release-47",
      "webAccessUri": "https://dev.azure.com/..."
    }
  }
}

Your external test trigger service receives this webhook and starts the appropriate test suite.

Receiving webhooks in Azure Functions

// Azure Function that receives the webhook and triggers tests
import { app, HttpRequest, HttpResponseInit } from '@azure/functions'
 
app.http('triggerTests', {
  methods: ['POST'],
  handler: async (request: HttpRequest): Promise<HttpResponseInit> => {
    const payload = await request.json()
    const environment = payload.resource.environment.name
 
    if (environment === 'Staging') {
      // Trigger the test pipeline via Azure DevOps REST API
      await fetch(
        `https://dev.azure.com/${ORG}/${PROJECT}/_apis/pipelines/${PIPELINE_ID}/runs?api-version=7.1`,
        {
          method: 'POST',
          headers: {
            Authorization: `Basic ${Buffer.from(`:${PAT}`).toString('base64')}`,
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            resources: { repositories: { self: { refName: 'refs/heads/main' } } },
            variables: {
              TARGET_ENV: { value: 'staging', isSecret: false },
            },
          }),
        }
      )
    }
 
    return { status: 200, body: 'Test trigger sent' }
  },
})

Bug notification workflow

Automatically notify developers when a bug is assigned to them:

  1. Service Hooks → New → Web Hooks
  2. Event: Work item updated
  3. Filter: Work item type = Bug, Field changed = Assigned To
  4. Webhook URL: your notification service

The notification service sends a Teams/Slack DM to the newly assigned developer with the bug title, priority, and a direct link.


Common errors and fixes

Error: Service hook fires but Teams notification doesn't appear Fix: Test the webhook URL independently with curl -X POST [url] -d '{"text":"test"}'. If this works, the issue is in the Azure DevOps configuration. If not, the Teams webhook may have expired — regenerate it.

Error: Custom webhook sends but the external system doesn't trigger Fix: The external system must return HTTP 200–299 within 60 seconds. If it returns an error or times out, Azure DevOps marks the hook as failed and may disable it after repeated failures. Check the hook's History tab in Service Hooks settings.

Error: Service hook triggers for all builds, not just the regression pipeline Fix: Add a filter: Pipeline name = [exact pipeline name]. Without filters, the hook fires for every build in the project.

Error: Service hook history shows "Exceeded retry limit — hook disabled" Fix: Re-enable the hook in Service Hooks → [Hook] → Enable. Fix the receiving endpoint so it responds quickly, then re-enable.

Free newsletter

Stay ahead in AI-driven QA

Get practical tutorials on test automation, AI testing, and quality engineering — straight to your inbox. No spam, unsubscribe any time.

Discussion

Sign in with GitHub to comment · powered by Giscus