Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022 | Azure DevOps Server 2020
Use service hooks to notify non-Microsoft systems about events that occur in your project. A custom consumer sends an HTTP message to the endpoint defined in your extension's manifest.
Tip
If you're starting a new Azure DevOps extension, try these maintained sample collections first—they work with current product builds and cover modern scenarios (for example, adding tabs on pull request pages).
- Azure DevOps extension sample (GitHub)—a compact starter sample that demonstrates common extension patterns: https://github.com/microsoft/azure-devops-extension-sample
- Azure DevOps extension samples (legacy collection and contributions guide)—install to inspect UI targets, or view the source: https://marketplace.visualstudio.com/items/ms-samples.samples-contributions-guide and https://github.com/Microsoft/vso-extension-samples/tree/master/contributions-guide
- Microsoft Learn samples (browse Azure DevOps samples)—curated, up-to-date samples across Microsoft docs: /samples/browse/?terms=azure%20devops%20extension
If a sample doesn't work in your organization, install it into a personal or test organization and compare the extension manifest's target IDs and API versions with the current docs. For reference and APIs, see:
This article walks through developing an extension that implements a sample consumer service, which includes the following events and actions.
- Supported events that trigger the following actions:
- Code pushed
- Pull request created
- Pull request updated
- Supported actions to take when events occur:
- Send an HTTP message
Note
This article refers to the home directory for your project as home.
For more information, see the Extension example GitHub repo. For a list of all supported events you can use as triggers for your custom consumer extension, see List of event types.
Tip
Check out our newest documentation on extension development using the Azure DevOps Extension SDK.
How service hooks work
Service hook publishers define a set of events. Subscriptions listen for the events and define actions that run when an event triggers.
This diagram shows the general service hook flow: publishers emit events, subscriptions match events, and actions run when a match occurs. In this article's example, an extension implements the consumer. When a supported event occurs, the consumer's configured action sends an HTTP message to the endpoint you specify in the extension manifest.
Create the extension
Add the specific contribution for custom consumer implementation to your basic manifest file. See the following example of how your manifest should look after you add the contribution.
{
"manifestVersion": 1,
"id": "samples-service-hooks-consumer",
"version": "0.1.2",
"name": "Service Hooks Sample",
"description": "A simple extension that demonstrates how to contribute a consumer service into service hooks.",
"publisher": "fabrikam",
"public": false,
"icons": {
"default": "images/logo.png"
},
"scopes": [],
"files": [
{
"path": "images",
"addressable": true
}
],
"content": {
"details": {
"path": "readme.md"
}
},
"categories": [
"Developer samples"
],
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"contributions": [
{
"id": "consumer",
"type": "ms.vss-servicehooks.consumer",
"targets": [
"ms.vss-servicehooks.consumers"
],
"properties": {
"id": "consumer",
"name": "Sample Consumer",
"description": "Sample consumer service",
"informationUrl": "https://aka.ms/vsoextensions",
"inputDescriptors": [
{
"id": "url",
"isRequired": true,
"name": "URL",
"description": "URL to post event payload to",
"inputMode": "textbox"
}
],
"actions": [
{
"id": "performAction",
"name": "Perform action",
"description": "Posts a standard event payload",
"supportedEventTypes": [
"git.push",
"git.pullrequest.created",
"git.pullrequest.updated"
],
"publishEvent": {
"url": "{{{url}}}",
"resourceDetailsToSend": "all",
"messagesToSend": "all",
"detailedMessagesToSend": "all"
}
}
]
}
}
]
}
Note
Remember to update the publisher property.
For each contribution in your extension, the manifest defines the following items.
- Type of contribution - consumer service (ms.vss-servicehooks.consumer) in this case.
- Contribution target - consumer services (ms.vss-servicehooks.consumers) in this case.
- Properties that are specific to each type of contribution.
Consumers have the following properties.
| Property | Description |
|---|---|
| id | Unique ID for your consumer service. |
| name | Name of the custom consumer, which is visible during service hook subscription creation. |
| description | Describes your consumer service. |
| informationUrl | Find more info about your extension. |
| inputDescriptors | Inputs to be used by users that are creating subscriptions with the consumer service. |
| actions | Describes the actions to take and which events trigger those actions. |
Actions for your consumer have the following properties:
| Property | Description |
|---|---|
| id | ID for your action service. |
| name | Name of the action. |
| description | Detailed description of the action. |
| supportedEventTypes | Array of trigger types for which this action can be used. For more information, see List of event types. |
| publishEvent.url | The endpoint URL that receives the HTTP message. You can template this value with tokens from the inputDescriptors; users provide the actual values when they create the subscription. |
- Deploy your extension to your Azure DevOps organization and test it.