Closed okainov closed 3 years ago
Can you provide samples of both webhooks? And point out what values it is you are looking for.
Sure https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment
{
"issue": {
"number": 1,
...
}
...
}
https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request
...
{
"number": 2,
...
}
I added a feature here: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github/github-pull-request-and-issue-comment.feature
With that feature you would need to check, in your build script, if pull_request_number
or issue_number
variable is available and use the one that is available.
Is the issue-comment
webhook content really what you are getting? Looks really strange if one opens a pull request on X and the webhook contains a link to an issue:
{
"action": "created",
"issue": {
"url": "https://api.github.com/repos/Codertocat/Hello-World/issues/X",
...
And this is relevant because you may want to use that to filter out issue-comment
comments that are not on a pull request.
Welcome to the wonderful GitHub API, yes, it is as dirty and as contrintuitive as hell. That's why I asked :)
With that feature you would need to check, in your build script, if pull_request_number or issue_number variable is available and use the one that is available.
I think you didn't get the whole point :) Correct me if I'm wrong, but typically one uses webhooks to start jobs. Start mean, apart of others, checkout. Checkout Jenkinsfile and then code. Checkout should be done from a branch. Checkout is done before any script/groovy logic is executed. It's not possible by definition in Jenkins to "check in my build script" when one needs to understand what to checkout.
Are you saying you want to:
Jenkinsfile
.Jenkinsfile
?
And this is not multibranch pipeline? Just ordinary pipeline?Perhaps it helps that if you configure variables like:
| variable | expression | expressionType | defaultValue | regexpFilter |
| issue_number | $.issue.number | JSONPath | | |
| pull_request_number | $.pull_request.number | JSONPath | | |
You the value of $issue_number$pull_request_number
will be the number
. As one variable will be empty and one will be the number
.
I think it should work if you also add the same variables in "this job is parameterized" as described here: https://github.com/jenkinsci/generic-webhook-trigger-plugin#default-values
You the value of $issue_number$pull_request_number will be the number. As one variable will be empty and one will be the number.
Yeah that's kind of the same what I came up with couple of days ago. Just we use $..number
as Jsonpath for GITHUBPR variable and then use GITHUBPR_0.
But while it works, I find it quite ugly :(
In this folder https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/github I see several useful examples. However it misses the case of triggering on issue_comment event.
Especially interesting part is how to make webhook trigger actually work on both
pull_request
andissue_comment
events. The reason is thatnumber
which is ID of pull request is placed in different JSON places in the payload of those webhooks. And so far I have seen no any option how can I extract "one of" or "first" value from JSONPath.What I kind of expect is
$..number[0]
, but this unfortunately doesn't work.