jenkinsci / generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
https://plugins.jenkins.io/generic-webhook-trigger
404 stars 159 forks source link

Parse different JSON patterns with JSONPath #193

Closed galindro closed 3 years ago

galindro commented 3 years ago

This is just a question, not a bug report.

I'm using this plugin with Bitbucket server. I need to trigger a build when someone push a commit to a branch and/or someone open/make a comment on a PR. As you may know, bitbucket sends two different JSON payloads for repository events and PR events.

I would like to extract the SHA1 commit hash (or branch, doesn't really matter) for both payload types and place it on a variable which has the same name of a build parameter.

For example: to get the SHA1 commit has from a PR payload event, I need this JSONPath: $.pullRequest.fromRef.latestCommit and to get the hash from a Repository payload event, I need this expression: $.changes[0].toHash

How could I extract those values with a single JSONPath expression? Shall I declare two Post content parameters with the same Variable name and different expressions, one for each payload?

tomasbjerre commented 3 years ago

You can probably ask about JSONPath on Stackoverflow. I donr know how to do that.

I would probably create 2 jobs in this case.

galindro commented 3 years ago

Hi @tomasbjerre . It seems that it isn't necessary in Bitbucket 7. They have introduced a new webhook - 'Source branch updated' -> https://jira.atlassian.com/browse/BSERV-10279. I'll close this ticket.

Tks!