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

Multibranch Pipeline triggering broken #319

Open medianick opened 3 days ago

medianick commented 3 days ago

I'm suspecting that #305 may have broken our ability to trigger Multibranch Pipeline jobs via the Generic Webhook Trigger. These are jobs with a triggers section in their Jenkinsfile like this:

    triggers {
      GenericTrigger(
        causeString: 'Label applied',
        genericVariables: [
          [defaultValue: '', key: 'TRIGGER_ACTION', value: '$.action'],
          [defaultValue: '', key: 'LABEL_NAME', value: '$.label.name']
        ],
        token: 'some_token'
      )
   }

It appears that after our upgrade from 2.0.2 to 2.2.0, new MultiBranch Pipeline jobs -- i.e., individual branch/PR jobs created (via branch indexing) by a Multibranch Pipeline after this plugin upgrade was applied -- are no longer found. This means that the invoke?token=some_token webhook deliveries for MBP jobs created entirely after this upgrade fail (HTTP 404) with this:

{
    "jobs": null,
    "message": "Did not find any jobs with GenericTrigger configured!\nA token was supplied.\n"
}

And webhook deliveries for MBP jobs that already existed prior to the upgrade only list the older jobs in the webhook response -- i.e., those branches/PRs that existed prior to the upgrade -- and the newer jobs are not triggered at all.

This seems to be the result of either 2.2.0 or 2.2.1. We've been running 2.2.0 since April 26th and 2.2.1 since May 23rd.

tomasbjerre commented 3 days ago

Probably same problem as #311 and #312. Solution is to upgrade Jenkins.

I'll probably make a new release with this new version of Jenkins as required, there are several issues like this one lately.

medianick commented 2 days ago

Indeed, upgrading to Jenkins 2.452.2 has resolved the issue. Thanks for the guidance, @tomasbjerre!

medianick commented 2 days ago

Actually, this is improved (with 2.452.2 installed), but not totally resolved.

The original branch I was testing with in my Multibranch Pipeline job is now getting detected (and is visible in the response payload when calling the webhook). So, that's the improvement, and it works perfectly for that original branch.

However, I created a new branch -- which the MBP picked up via the usual branch indexing, so it exists in Jenkins -- but triggering the webhook (either via GitHub, or manually) does not list that branch in the response; it still only shows the original branch. As a result, actions that should be triggered by this webhook for this new branch are not triggered at all.

medianick commented 2 days ago

To provide a little more background, my setup is a little complex:

medianick commented 2 days ago

I've also tried creating an entirely new MBP job (just copying from the existing one) but the GWT webhook isn't finding that either. So, it's basically as if the only job and branch that works is the one that existed at the point we upgraded to 2.452.2 (and Jenkins was restarted).

tomasbjerre commented 2 days ago

It works on restart because this plugin will gather all jobs on startup: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/3954ee99f8c8801877f6a9b998fe7fdcaa78e6d7/src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java#L60

It is a problem with the updating.

medianick commented 2 days ago

It is a problem with the updating.

Is that likely to be a problem in Jenkins itself or in this plugin?

tomasbjerre commented 2 days ago

It is a problem with the updating.

Is that likely to be a problem in Jenkins itself or in this plugin?

Or maby multibranch pipeline plugin.

medianick commented 7 hours ago

Upon further testing, it's possible this isn't specific to Multibranch Pipelines. I created a simple Job DSL script that seeds a (regular, not Multibranch) Pipeline job with GenericTrigger in its (inline, not from SCM) script, and the GWT webhook URL is not finding that seeded job either. E.g.:

pipelineJob('TestJob') {
  definition {
    cps {
      sandbox(true)
      script("""
pipeline {
    agent none
    triggers {
        GenericTrigger(
... etc.

Possibly it will find it the next time our Jenkins instance is restarted.

medianick commented 7 hours ago

I also tried copying a manually created Pipeline job that uses GenericTrigger (which is working fine) to a new job, and the new copy was found (listed in the webhook response) but not triggered ("triggered":false) until I opened and re-saved its configuration.