microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.19k stars 926 forks source link

Resource webhook trigger is misdocumented? #535

Closed joshspicer closed 3 years ago

joshspicer commented 3 years ago

I am working on connecting an ADO YAML pipeline to be triggered by a webhook via service connection.

Looking at the documentation here on how to supply a filter

is not correct, as visible through the YAML intellisense.

image

I've been unable to get filtering to work on my ADO pipeline - some advice here would be appreciated :)

mjroghelia commented 3 years ago

@joshspicer This is telling you that you need a - in front of "$.action". Filters is an array of mappings, not a mapping.

joshspicer commented 3 years ago

I was just copying the docs on this repo to illustrate the problem. Adding a - doesn't help :( image

I don't get any syntactic errors when I set it up like below, but that doesn't actually work (my incoming webhooks are not filtered by this key/value pair image

joshspicer commented 3 years ago

Am I missing something on how filters is supposed to behave in the first place? I want to filter based on the JSON webhook data that I receive on this pipeline. From GitHub, when a "release" webhook is sent, it's sent 3 times (with three distinct actions.)

The JSON looks like this:

{
  "action": "SOME_VALUE",
 ...
 ...
}

When SOME_VALUE == "released" I want this pipeline to run, otherwise I don't want it to run.

mjroghelia commented 3 years ago

@joshspicer Sorry I can't help more. The document you are referring to is a design doc and as stated in the README not maintained as permanent documentation of the product.

joshspicer commented 3 years ago

Hey @mjroghelia - I understand that perhaps this repo isn't the best source of information for how to use this feature. I've also tried referencing the permanent documentation on docs.microsoft.com (found here and announced here).

As you can see from my screenshot above, i've copied what is in the docs, but the filter does not get applied (My pipeline runs 3 times, even when my filter's value at the given path does not equal what is in the YAML.

joshspicer commented 3 years ago

For reference, this is what the docs say vs what I have in my pipeline. The JSON webhook body is sent as I shared above.

I am sent three requests from Github when a release is created, with three different actions. My goal is to filter by the action key.

The documentation

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

My pipeline

# Triggered on a webhook sent from 
# a GitHub repo
resources:
  webhooks:
    - webhook: DefaultImageCreationWebhook
      connection: DefaultImageCreationConnection
      filters:
        - path: "action"
          value: "released" 
anatolybolshakov commented 3 years ago

Hi @joshspicer I would suggest to create ticket on https://developercommunity.visualstudio.com/search?space=21 to get right eyes on it and further help - this repo is for yaml templates mostly

joshspicer commented 3 years ago

sure, ill do that.

joshspicer commented 3 years ago

Link to the devcon issue, for anyone that stumbles upon this issue in the future

https://developercommunity.visualstudio.com/t/filters-on-resource-webhook-trigger-are-not-applie/1404363