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

Generic webhook does not trigger Jenkins job #170

Closed dsakilesh closed 3 years ago

dsakilesh commented 3 years ago

I am trying to trigger a specific jenkins job from generic webhook trigger plugin but the job is not triggering though i get a successful connection from bitbucket to Jenkins.

Response from bitbucket webhook url :

https://jenkins.com/generic-webhook-trigger/invoke?&token=TEST_HOOK

{"jobs":{"TestFolder/ABCD/master":{"regexpFilterExpression":"$repository refs/heads/master","triggered":false,"resolvedVariables":{"ref":"refs/heads/master","repository":"ABCD"},"regexpFilterText":"refs/heads/master","id":0,"url":""},"TestFolder/ABCD/PR-1":{"regexpFilterExpression":"$repository refs/heads/PR-1","triggered":false,"resolvedVariables":{"ref":"refs/heads/master","repository":"ABCD"},"regexpFilterText":"refs/heads/master","id":0,"url":""}},"message":"Triggered jobs."}

Response from the curl command:

curl -X POST -i -H "Content-Type: application/json" --url 'https://jenkins.com/generic-webhook-trigger/invoke?token=TEST_HOOK' -d '{ "ref": "refs/heads/master", "repository": "ABCD" }'

{"jobs":{"TestFolder/ABCD/master":{"regexpFilterExpression":"$repository refs/heads/master","triggered":false,"resolvedVariables":{},"regexpFilterText":"$ref","id":0,"url":""},"TestFolder/ABCD/PR-1":{"regexpFilterExpression":"$repository refs/heads/PR-1","triggered":false,"resolvedVariables":{},"regexpFilterText":"$ref","id":0,"url":""}},"message":"Triggered jobs."}

I get the same response with triggered:false , but I want the jobs to be triggered as part of the commit to a branch.

I have the below generic trigger configuration as part of my Jenkinsfile:

triggers {
    GenericTrigger(
     genericVariables: [
      [key: 'ref', value: '$.changes[0].ref.id'],
      [key: 'repository', regexpFilter: '[^a-z_-]', value: '$.repository.slug']
     ],

     causeString: 'Triggered on $ref',

     token: 'TEST_HOOK',

     printContributedVariables: true,
     printPostContent: true,

     silentResponse: false,

     regexpFilterText: '$ref',
     regexpFilterExpression: '$repository refs/heads/' + BRANCH_NAME
    )
  }

Our intention is to scan and trigger only a specific branch where a commit/push has happened and to avoid unecessary scan of all the existing branches. (which will consume lot of system resources)

Note : I have also tried multibranch webhook trigger which will trigger the job , where as generic webhook is not triggering.

multibranch webhook url:

https://jenkins.com/multibranch-webhook-trigger/invoke?&token=TEST_HOOK

But the disadvantage of mutibranch is it will scan all the branches which we do not want it to happen.

Let me know if you need more details.

Thanks in advance!

Regards, Akilesh D S

tomasbjerre commented 3 years ago

This plugin triggers builds. The scan-feature of multibranch is not a build. This plugin has, and will not have, any dependency on the multibranch pipeline. I think that way of working is wrong: https://www.jenkins.io/blog/2019/12/14/generic-webhook-trigger-plugin/

Your job is not triggering because of $repository. It does not resolve to anything and the text only has $ref:

   regexpFilterText: '$ref',
   regexpFilterExpression: '$repository refs/heads/' + BRANCH_NAME

If you want to use this plugin together with multibranch you will need the multibranch webhook trigger to trigger the scanning. And this plugin can trigger the builds.

dsakilesh commented 3 years ago

Hi Tomas Bjerre,

We currently have multibranch pipeline jobs and we want a functionality where in only the branch that triggered jenkins should be scanned. We do not want to unnecessarily scan all the branches as it consumes system resources.

So is there a way that we can achieve this with multibranch pipeline?

Thanks in advance!

Regards, Akilesh D S

tomasbjerre commented 3 years ago

I dont think so. You should open an issue on that plugin.