azureazure-devopsazure-pipelineswebhooksazure-webhooks

How can I extract the runtime parameter name from azure devops? I want to extract the webhook name that triggered the pipeline?


I am trying to extract the webhook that triggered the pipeline since azure sent this info in the runtime parameter in JSON format. I want to retrieve the name.

I want to retrieve this from the runtime parameters

I tried to convert the parameter as follows:

echo ${{ convertToJson(parameters) }} | sed -E 's/^([^:]+) :.*/\1/  ```

to resume I have 2 webhooks in my pipeline and I want to retrieve the webhook that triggered the pipeline to choose which job will execute

I tried this  simple test **yet it keep skipping without any output:

resources:
   webhooks:
     - webhook: webhook1
       connection: ServiceConnection1
     - webhook: webhook2
       connection: ServiceConnection2

 trigger:
   branches:
     include:
       - main

 stages:
   - stage: Stage1
     condition: eq(variables['resources.webhooks[2].webhook'], 'webhook1')
     jobs:
       - job: Job1
         steps:
           - script: echo "This stage is triggered by webhook1"

   - stage: Stage2
     condition: eq(variables['resources.webhooks[2].webhook'], 'webhook2')
     jobs:
       - job: Job1
         steps:
           - script: echo "This stage is triggered by webhook2" ```

Solution

  • How can I extract the runtime parameter name from azure devops? I want to extract the webhook name that triggered the pipeline?

    To meet your requirement, you can use the Pipeline variable: Resources.TriggeringAlias. It will show the webhook name that trigger the pipeline.

    Here is an example:

    resources:
      webhooks:
        - webhook: webhook1        
          connection: ServiceConnection1   
        - webhook: webhook2
          connection: ServiceConnection2
    
    stages:
    - stage: Stage1
      condition: eq(variables['RESOURCES.TRIGGERINGALIAS'], 'webhook1')
      jobs:
      - job: Job1
        steps:
        - script: echo "This stage is triggered by webhook1"
    
    - stage: Stage2
      condition: eq(variables['RESOURCES.TRIGGERINGALIAS'], 'webhook2')
      jobs:
      - job: Job1
        steps:
        - script: echo "This stage is triggered by webhook2" 
    

    When the pipeline is triggered by one of the webhook, it will run the target stage.

    Result:

    enter image description here