Joao Pedro Martins
Joao Pedro Martins

Reputation: 53

GenericWebhookTrigger not triggering specific build

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":""}}}}

Upvotes: 2

Views: 3591

Answers (2)

Karthiga
Karthiga

Reputation: 26

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.

Upvotes: 1

F. Norbert
F. Norbert

Reputation: 871

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.

Upvotes: 1

Related Questions