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
410 stars 161 forks source link

JOB DSL for webhook trigger plugin #195

Closed vishnujanardhanan closed 3 years ago

vishnujanardhanan commented 3 years ago

When reporting a bug, please try to provide as much information as possible.

I wanted to trigger builds only when there is push to master branch, so i have configured the below job DSL to handle it. However no nuilds seems to get triggerred after i added them. If i just have tokens in the jobdsl it triggers the build for push on every branch. Can you please help?

triggers {
    genericTrigger {
        genericVariables {
            genericVariable {
                key("ref")
                value("\$.ref")
                expressionType("JSONPath") //Optional, defaults to JSONPath
                regexpFilter("") //Optional, defaults to empty string
                defaultValue("") //Optional, defaults to empty string
            }
        }
        token('apiinfra')
        printPostContent(true)
        regexpFilterText("\$ref")
        regexpFilterExpression("^(refs\\/heads\\/master)\$")
    }
}

post content logged in the jenkins build log was empty. I can see the post content from webhook in jenkins though.

tomasbjerre commented 3 years ago

How do you trigger the plugin? And what is the response of that?

vishnujanardhanan commented 3 years ago

@tomasbjerre A webhook is configured from git which triggers on every push. response is a 200 on git. post parameters seems to be empty on jenkins workspace logs if I enable the flag in webhook trigger plugin. So not sure whether i;m missing something here

tomasbjerre commented 3 years ago

I need to know exactly what that webhook contains. And exactly what the response is, not only http code.

vishnujanardhanan commented 3 years ago

ok, can i private msg you? Not able to post them here due to org policies

tomasbjerre commented 3 years ago

Post it here and remove sensitive parts. Or change its content.

Den tis 15 dec. 2020 15:30Vishnu Janardhanan notifications@github.com skrev:

ok, can i private msg you? Not able to post them here due to org policies

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/195#issuecomment-745327837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADLKE22YSNHB6ZTFECYDRTSU5XJFANCNFSM4UTIGSMA .

vishnujanardhanan commented 3 years ago

{ "ref": "refs/heads/master", "before": "08b7e2c1c8db24a1701ceda8336bb1d12bcf4b5e", "after": "2683b259689c50c80a2eaadeb228b9968014b2bc", "repository": { "id": 25334, "node_id": "vvvvvvvv", "name": "xrepo", "full_name": "xorg/xrepo", "private": false, "owner": { "name": "xxxx", "email": null, "login": "xxxx", "id": 72, "node_id": "vvvvvvv", "avatar_url": "https://github.xxx.org/avatars/u/72?", "gravatar_id": "", "url": "https://github.xxx.org/api/v3/users/t", "html_url": "https://github.xxx.org/xxx", "followers_url": "https://github.xxx.org/api/v3/users/xxx/followers", "following_url": "https://github.xxx.org/api/v3/users/xxx/following{/other_user}", "gists_url": "https://github.xxx.org/api/v3/users/xxx/gists{/gist_id}", "starred_url": "https://github.xxx.org/api/v3/users/xxx/starred{/owner}{/repo}", "subscriptions_url": "https://github.xxx.org/api/v3/users/xxx/subscriptions", "organizations_url": "https://github.xxx.org/api/v3/users/xxx/orgs", "repos_url": "https://github.xxx.org/api/v3/users/xxx/repos", "events_url": "https://github.xxx.org/api/v3/users/xxx/events{/privacy}", "received_events_url": "https://github.xxx.org/api/v3/users/xxx/received_events", "type": "Organization", "site_admin": false }, "html_url": "https://github.xxx.org/xorg/xrepo", "description": null, "fork": false, "url": "https://github.xxx.org/xorg/xrepo", "forks_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/forks", "keys_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/keys{/key_id}", "collaborators_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/collaborators{/collaborator}", "teams_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/teams", "hooks_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/hooks", "issue_events_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/issues/events{/number}", "events_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/events", "assignees_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/assignees{/user}", "branches_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/branches{/branch}", "tags_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/tags", "blobs_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/git/blobs{/sha}", "git_tags_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/git/tags{/sha}", "git_refs_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/git/refs{/sha}", "trees_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/git/trees{/sha}", "statuses_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/statuses/{sha}", "languages_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/languages", "stargazers_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/stargazers", "contributors_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/contributors", "subscribers_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/subscribers", "subscription_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/subscription", "commits_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/commits{/sha}", "git_commits_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/git/commits{/sha}", "comments_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/comments{/number}", "issue_comment_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/issues/comments{/number}", "contents_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/contents/{+path}", "compare_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/compare/{base}...{head}", "merges_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/merges", "archive_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/{archive_format}{/ref}", "downloads_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/downloads", "issues_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/issues{/number}", "pulls_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/pulls{/number}", "milestones_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/milestones{/number}", "notifications_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/notifications{?since,all,participating}", "labels_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/labels{/name}", "releases_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/releases{/id}", "deployments_url": "https://github.xxx.org/api/v3/repos/xorg/xrepo/deployments", "created_at": 1557722507, "updated_at": "2020-12-14T08:39:16Z", "pushed_at": 1608026206, "git_url": "git://github.xxx.org/xorg/xrepo.git", "ssh_url": "git@github.xxx.org:xorg/xrepo.git", "clone_url": "https://github.xxx.org/xorg/xrepo.git", "svn_url": "https://github.xxx.org/xorg/xrepo", "homepage": null, "size": 4587, "stargazers_count": 0, "watchers_count": 0, "language": "HCL", "has_issues": true, "has_projects": true, "has_downloads": true, "has_wiki": true, "has_pages": false, "forks_count": 2, "mirror_url": null, "archived": false, "disabled": false, "open_issues_count": 6, "license": null, "forks": 2, "open_issues": 6, "watchers": 0, "default_branch": "master", "stargazers": 0, "master_branch": "master", "organization": "xxx" }, "pusher": { "name": "xuser", "email": "sdfsdfsdf@in.xxx.com" }, "organization": { "login": "xxx", "id": 72, "node_id": "vvvvv", "url": "https://github.xxx.org/api/v3/orgs/xxx", "repos_url": "https://github.xxx.org/api/v3/orgs/xxx/repos", "events_url": "https://github.xxx.org/api/v3/orgs/xxx/events", "hooks_url": "https://github.xxx.org/api/v3/orgs/xxx/hooks", "issues_url": "https://github.xxx.org/api/v3/orgs/xxx/issues", "members_url": "https://github.xxx.org/api/v3/orgs/xxx/members{/member}", "public_members_url": "https://github.xxx.org/api/v3/orgs/xxx/public_members{/member}", "avatar_url": "https://github.xxx.org/avatars/u/72?", "description": null }, "enterprise": { "id": 1, "slug": "xxx-ltd", "name": "xxx Ltd.", "node_id": "vvvvv", "avatar_url": "https://github.xxx.org/avatars/b/1?", "description": null, "website_url": null, "html_url": "https://github.xxx.org/enterprises/xxx-stores-ltd", "created_at": "2019-04-06T02:34:16Z", "updated_at": "2019-04-06T02:37:08Z" }, "sender": { "login": "xuser", "id": 1338, "node_id": "vvvv=", "avatar_url": "https://github.xxx.org/avatars/u/1338?", "gravatar_id": "", "url": "https://github.xxx.org/api/v3/users/xuser", "html_url": "https://github.xxx.org/xuser", "followers_url": "https://github.xxx.org/api/v3/users/xuser/followers", "following_url": "https://github.xxx.org/api/v3/users/xuser/following{/other_user}", "gists_url": "https://github.xxx.org/api/v3/users/xuser/gists{/gist_id}", "starred_url": "https://github.xxx.org/api/v3/users/xuser/starred{/owner}{/repo}", "subscriptions_url": "https://github.xxx.org/api/v3/users/xuser/subscriptions", "organizations_url": "https://github.xxx.org/api/v3/users/xuser/orgs", "repos_url": "https://github.xxx.org/api/v3/users/xuser/repos", "events_url": "https://github.xxx.org/api/v3/users/xuser/events{/privacy}", "received_events_url": "https://github.xxx.org/api/v3/users/xuser/received_events", "type": "User", "site_admin": false }, "created": false, "deleted": false, "forced": false, "base_ref": null, "compare": "https://github.xxx.org/xorg/xrepo/compare/08b7e2c1c8db...2683b259689c", "commits": [ { "id": "75f416e29e44470690a228bc57a787f741b24", "tree_id": "4dc30553e7504093818412b77d902600251e", "distinct": false, "message": "adding path", "timestamp": "2020-12-15T12:01:18+05:30", "url": "https://github.xxx.org/xorg/xrepo/commit/75f416e29e44470690a228bc57a787878f741b24", "author": { "name": "xuser", "email": "sdfsdf@xxx.com", "username": "xuser" }, "committer": { "name": "xuser", "email": "sdfsfdsf@xxx.com", "username": "xuser" }, "added": [

  ],
  "removed": [

  ],
  "modified": [
    "infrastructure/01_mgmt/env/dev/master/config/config.xml"
  ]
},
{
  "id": "2683b259689c50c80a2eaadeb228b9968014b2bc",
  "tree_id": "4dc30553e7504093818412b706dc7d902600251e",
  "distinct": true,
  "message": "Merge pull request #422",
  "timestamp": "2020-12-15T15:26:46+05:30",
  "url": "https://github.xxx.org/xorg/xrepo/commit/2683b259689c50c80a2eaadeb228b9968014b2bc",
  "author": {
    "name": "xuser",
    "email": "xuser@in.xxx.com",
    "username": "xuser"
  },
  "committer": {
    "name": "GitHub Enterprise",
    "email": "noreply@github.xxx.com"
  },
  "added": [

  ],
  "removed": [

  ],
  "modified": [
    "infrastructure/01_mgmt/env/dev/master/config/config.xml"
  ]
}

], "head_commit": { "id": "2683b259689c50c80a2eaadeb228b9968014b2bc", "tree_id": "4dc30553e7504093818412b706dc7d902600251e", "distinct": true, "message": "Merge pull request #422", "timestamp": "2020-12-15T15:26:46+05:30", "url": "https://github.xxx.org/xorg/xrepo/commit/2683b259689c50c80a2eaadeb228b9968014b2bc", "author": { "name": "xuser", "email": "xuser@in.xxx.com", "username": "xuser" }, "committer": { "name": "GitHub Enterprise", "email": "noreply@github.xxx.com" }, "added": [

],
"removed": [

],
"modified": [
  "infrastructure/01_mgmt/env/dev/master/config/config.xml"
]

} }

tomasbjerre commented 3 years ago

Did you try without \\? like:

regexpFilterExpression("^(refs/heads/master)\$")

As described here: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github/github-push-specific-branches.feature#L10

vishnujanardhanan commented 3 years ago

@tomasbjerre thanks.. this filter worked -> regexpFilterExpression("^(refs/heads/master)\$")