azure-devopsazure-pipelinesworkflowwebhooksoffice365connectors

Using Webhook URL in Azure Pipeline to send Microsoft Teams Notification


I had built a pipeline which scans the Keyvaults and sends a Microsoft Teams notification using Webhook(Eonos Office Webhook) incase any Key/Certificate has expired/about to Expire. And the pipeline works perfectly, however since O365 connectors are deing depreciated, I am forced to use Microsoft Workflows to post a message from a Webhook Request.

For that I created a Workflow which 'Post to a channel when a webhook request is received' but when I replaced my current Eonos WebhookURL with the new Workflow URL, I am getting the following error:

enter image description here

this is the current configuration of the Workflow: enter image description here

And this is my powershell function which sends the notification using the WebhookURL: enter image description here

What I understand is that it needs a SAS token for authentification(maybe I am wrong) but I am not able to find a solution where/if a token needs to be generated or what needs to be integrated to send the notification successfully.

Update 27.08.2024

This is my updated configuration: enter image description here


Solution

  • Based on your description, I am able to invoke the sample Power AutoMate WebHook request in a pwsh task of Azure DevOps pipeline.

    enter image description here

    enter image description here

    enter image description here

    pool: # server
      vmImage: windows-latest
    
    steps:
    - pwsh: |
        $WebhookURL = "https://prod-xx.southeastasia.logic.azure.com:443/workflows/xxxxxx/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2ftriggers%2fmanual%2frun&sv=1.0&sig=xxxxxx"
        $messageParts = @(
          "123"
          "xyz"
        )
        $keyVault = "MyKeyVault"
        $message = @{
          'text' = ($messageParts -join "<br /><br />")
          'title' = "Key Vault: $keyVault"
        }
        $messageJson = $message | ConvertTo-Json -Depth 2
        Write-Host $messageJson
    
        Invoke-RestMethod -Method Post -Uri $WebhookURL -Body $messageJson -ContentType 'application/json'
    

    Please print those variables to double check if your pipeline had processed the expected values in $message, $keyVault and $messageJson.

    Image

    In case the error was caused by other script snippet, please share the relevant commands to investigate further.

    Besides, since you should be able to execute that script anywhere with the command tool sets, you may try to run it in local PowerShell prompt before integrating it in pipelines. It is easier to troubleshoot.