2

I have Jenkins running normally and a pipeline with specifications below. I set the pipeline configuration to use the Generic Webhook Trigger with the same configuration as specificated in pipeline. The webhook is also configured in my gitbucket repository to only send push triggers. But when I test it, the response is 200 and a body response with "triggered":false.

Pipeline:

pipeline {
    agent any
    triggers {
    GenericTrigger(
     genericVariables: [
        [key: 'ref', value: '$.ref']
     ],
     genericHeaderVariables: [
        [key: 'X-GitHub-Event', regexpFilter: '']
     ],

     causeString: 'Triggered on $ref',

     token: '123456',

     printContributedVariables: true,
     printPostContent: true,

     silentResponse: false,

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

    stages{...

Response body from gitbucket webhook:

{"status":"ok","data":{"triggerResults":{"testePipeline":{"id":0,"regexpFilterExpression":"refs/heads/master","regexpFilterText":"","resolvedVariables":{"ref":"","x_github_event":"","x_github_event_0":""},"triggered":false,"url":""}}}}
1
  • 1
    You need to have a valid value under the ref key. At the moment this one is missing. regexpFilterText and regexFilterExpression lines are useless. As for as I expected if the filter fails, the webhook won't get any id and url. The missing id and url will result this "triggered": false state. I will write further comments or solutions if I will go further with my very similar issue. :) Commented Oct 21, 2019 at 14:07

2 Answers 2

1

I had the same issue as above,

{
  "jobs": {
    "Test": {
      "regexpFilterExpression": "(refs/heads/Dev|refs/heads/master)",
      "triggered": false,
      "resolvedVariables": {
        "ref": ""
      },
      "regexpFilterText": "",
      "id": 0,
      "url": ""
    }
  },
  "message": "Triggered jobs."
}

The reason was my content type was not application/json in Github. Corrected it and the build ran fine.

Sign up to request clarification or add additional context in comments.

Comments

1

In my case, the problem was on the GitLab side. With this configuration:

triggers {
        GenericTrigger(
            genericVariables: [
                [key: 'user_name', value: '$.user_name'],
                [key: 'checkout_sha', value: '$.checkout_sha'],
                [key: 'web_url', value: '$.project.web_url'],
                [key: 'ref', value: '$.ref'],
                [key: 'tag', value: '$.ref', regexpFilter: 'refs/tags/'],
            ],

            causeString: '$user_name pushed tag $tag to $web_url referencing $checkout_sha',

            token: 'abc123',

            printContributedVariables: true,
            printPostContent: true,

            silentResponse: false,

            regexpFilterText: '$ref',
            regexpFilterExpression: '^refs/tags/.*'
        )
    }

I could use the Tag Push webhook, if I pushed a tag from my terminal or taged on the GitLab WebUI but couldn't do the same via the test "Tag Push" webhook button.

It turned out this is known issue: https://gitlab.com/gitlab-org/gitlab-foss/issues/52556 The request header will be the same push in both cases.

Request header and part of the body after a test Push trigger:


Content-Type: application/json
X-Gitlab-Event: Push Hook

{
  "object_kind": "push",
  "event_name": "push",
  "before": "ab5183fcf2d4e698f1cf6228d0c1532ac7815bcc",
  "after": "3045da963cc63720c3bbc3c1217ecf2708035bfe",
  "ref": "refs/heads/master",
.
.
.

Request header and part of the body after a test Tag Push trigger:

Content-Type: application/json
X-Gitlab-Event: Tag Push Hook

{
  "object_kind": "push",
  "event_name": "push",
  "before": "ab5183fcf2d4e698f1cf6228d0c1532ac7815bcc",
  "after": "3045da963cc63720c3bbc3c1217ecf2708035bfe",
  "ref": "refs/heads/master",
.
.
.

I highly recommend you check the request headers and the body too. Of course, the "triggered": false may come if your filters work properly. For example, if I send a regular push event, the result will be a success with a false trigger state. This is correct because the trigger worked well but your filter too.

1 Comment

Your solution is correct, but the problem I had required only one change on Gitbucket's side: the webhook configuration was set to send a x-www-form-urlencoded, while Jenkins awaits a JSON. Just like the requests you've shown. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.