Accessing Incoming WebHook JSON payload in Bash - Azure Pipelines

Viewed 501

I'm building an azure pipeline and using an Incoming WebHook as the trigger.

I need to access the data I'm sending in the JSON Payload in Bash, the documentation only has the following example in PowerShell and there no any other docs about how to access that Payload

resources:
  webhooks:
    - webhook: MyWebhookTrigger          ### Webhook alias
      connection: MyWebhookConnection    ### Incoming webhook service connection
      filters:
        - path: repositoryName      ### JSON path in the payload
          value: maven-releases     ### Expected value in the path provided
        - path: action
          value: CREATED
steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    ### JSON payload data is available in the form of ${{ parameters.<WebhookAlias>.<JSONPath>}}
    script: |
      Write-Host ${{ parameters.MyWebhookTrigger.repositoryName}}
      Write-Host ${{ parameters.MyWebhookTrigger.component.group}}

I tried to check the Environment Variables in bash but couldn't find anything there any pointers on what this means ${{ parameters.MyWebhookTrigger.repositoryName}} in Powershell and how can I do the same in bash?

1 Answers

Below is an example using Bash to write the value of part of the webhook payload.

Please note the extra pr: none and trigger: none in the example. This prevents the pipeline from being executed with non-webhook triggers that will result in an empty webhook payload... because it wasn't triggered by a webhook. Azure DevOps Pipeline Incoming Webhook from GitHub: Json Payload empty in pipeline

# file: azure-pipeline.yml

# These lines prevent default non-webhook events from executing the pipeline
pr: none
trigger: none

resources:
  webhooks:
    - webhook: BasicWebhook          ### Webhook alias
      connection: BasicWebhookConnection    ### Incoming webhook service connection


steps:
- script: |
    echo ${{parameters.BasicWebhook.repository}}
Related