azureazure-devopsazure-eventgrid

Is there a way to post from Azure Event grid to Azure DevOps incoming webhook


I would like to use the new Azure Update Manager and to have some kind of update orchestration. I want to be able to trigger an Azure DevOps pipeline via an incoming webhook. So I created the webhook in Azure DevOps, placed it as a resource in the pipeline and tested it successfully via postman

resources:
  webhooks:
    - webhook: mywebhook
      connection: mywebhook 

But when I want to create a Pre Maintenance event and call my Incoming Webhook In Azure DevOps, Event Grid would send a request to the Azure DevOps with the following body:

[
  {
    "id": "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66",
    "topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "subject": "",
    "data": {
      "validationCode": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6",
      "validationUrl": "https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/myeventsub/validate?id=0000000000-0000-0000-0000-00000000000000&t=2022-10-28T04:23:35.1981776Z&apiVersion=2018-05-01-preview&token=1A1A1A1A"
    },
    "eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
    "eventTime": "2022-10-28T04:23:35.1981776Z",
    "metadataVersion": "1",
    "dataVersion": "1"
  }
]

However this body is not accepted by Azure DevOps because the payload is an array and not a single object thus my pipeline is not triggered and also I cannot see the validation URL to validate my Event Grid subscription. I tried to use a custom event schema but due to the fact that I use Maintenance Configuration topic type, custom event schema is not possible.

So is there a way to communicate between Azure Update manager and Azure DevOps using a webhook to facilitate Update orchestration? Azure Update Manager/Event Grid

  1. Created webhook in Azure Devops.

  2. Successfully called the webhook and triggered the pipeline using Postman POST https://dev.azure.com/myorg/_apis/public/distributedtask/webhooks/mywebhook?api-version=6.0-preview

  3. When I try to access the webhook from Azure Update Manager/Event grid - the webhook is not triggered due to the payload mismatch.


Solution

  • I can reproduce the issue from my side. The pipeline can be triggered by the webhook successfully when I post from Postman. However, if I add https://dev.azure.com/<ADO Organization>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview as the endpoint when create an event grid, it will fail with error message Webhook validation handshake failed for ... Http POST request retuned 2XX response with response body . When a validation request is accepted without validation code in the response body, Http GET is expected on the validation url included in the validation event(within 10 minutes). It seems that DevOps doesn't send response to event grid, so that the validation will fail.

    As a workaround, you can create a logic app or function app. Set your app URL as webhook endpoint when creating the event. Then trigger the DevOps pipeline via your app.