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

Prioritze payload | Get two payloads or change order of recieved payloads #252

Closed noraroxette closed 1 year ago

noraroxette commented 1 year ago

Hi!

We have a job in Jenkins which we want to trigger on push, but also on pull request opened and pull request branch updated (from Bitbucket). We use the Generic Webhook Trigger plugin with a token.

However, by doing this, a push to the pull request branch also fires the regular push webhook (makes sense as they are both in fact a push event). Whenever there is an event related to Pull Request, that is the payload we want, but we only receive the "repo:refs_changed" event-payload. It seems that Jenkins only recieves the payload from one of the triggers, the push event and not the pull request branch updated.

10:10:00  Generic Cause
10:10:00  Generic Cause
10:10:00  GenericWebhookEnvironmentContributor
10:10:00   Received:
10:10:00  
10:10:00  {"eventKey":"repo:refs_changed",.......}
10:10:00  ---continue with something

But as you can see on this log from jenkins, it has been triggered twice, which is correct (the push, and pull request branch updated event). Is there any way to add a delay to the push event on the webhook or somehow change the order the payloads are sent from Bitbucket so that we can continue or Jenkinsjob with the payload we want (the pull request payload if this exist)? Or any way to get both?

Thank you for this plugin :)

tomasbjerre commented 1 year ago

See this if you want each individual event to trigger one job: https://github.com/jenkinsci/generic-webhook-trigger-plugin#trigger-exactly-one-build

If you want to override the delay, there is a Override Quiet Period option. But I don't think that solves your problem.

luisgois commented 1 year ago

Hi @tomasbjerre, thanks for this plugin!

Despite its undeniable usefulness, we overlooked this detail and wish to trigger Jenkins per Bitbucket webhook event and repository from where it originates (i.e. for each distinct payload) and not being an apparent hostage of "If this plugin gets invoked by many webhooks at the same time it may trigger only one build".

Can you please confirm that if a multiple pull requests get merged in multiple repositories "at the same time", they could potentially trigger a single build?

Since Bitbucket webhooks don't allow the URL to be built dynamically (e.g. using variables), one way to insure the job builds for each event in each repository would be to have a distinct set of URL parameters such that it's unique for each event+repository pair.

As a workaround, I've attempted to fix this by changing the token URL parameter, effectively triggering distinct Jenkins jobs. However this isn't a desirable solution. We want to have a single webhook triggered Jenkins job that in turn triggers specific jobs to handle the event per repository (typically a pipeline, otherwise a freestyle job with parametrization extracted from the payload).

Thanks in advance.

tomasbjerre commented 1 year ago

Yes, I can confirm that. But if you do as I try to explain in the readme, you will not have that problem. Just pic something unique from the payload, with jsonpath, and assign it to a variable in the plugin. Make the job parameterized with a parameter having same name as the variable.

tomasbjerre commented 1 year ago

I released 1.86.1 now and it should solve the problem. See changelog. Open issue again if not working.