HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

GitHub Payload in Jenkins

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
jenkinsgithubpayload

Problem

I'm using the GitHub plugin with Jenkins, and I'm trying to figure out how I can access the webhook payload. I'm aware that the Generic Webhook Trigger has this ability, as well as the GitHub Pull Request plugin, but this plugin seems more suitable to an automated workflow.

On that note, what I'm looking at is importing the class and parsing the payload, similar to what is done in the troubleshooting section here.

This sample works, but only prints the class:

import org.kohsuke.stapler.StaplerRequest
import org.jenkinsci.plugins.github.webhook.GHEventPayload
import org.jenkinsci.plugins.github.webhook.GHEventPayload.PayloadHandler

payload = new PayloadHandler()
println(payload)


This sample wants more info, but I'm not handy enough with Java to know what it's asking for:

import org.kohsuke.stapler.StaplerRequest
import org.jenkinsci.plugins.github.webhook.GHEventPayload
import org.jenkinsci.plugins.github.webhook.GHEventPayload.PayloadHandler

payload = new PayloadHandler()
println(payload.parse())


According to the source code, that's the method I need, but it produces the following error:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.github.webhook.GHEventPayload$PayloadHandler.parse() is applicable for argument types: (java.lang.Class) values: [interface org.jenkinsci.plugins.github.webhook.GHEventPayload]
Possible solutions: parse(org.kohsuke.stapler.StaplerRequest, java.lang.annotation.Annotation, java.lang.Class, java.lang.String), parse(org.kohsuke.stapler.StaplerRequest, org.jenkinsci.plugins.github.webhook.GHEventPayload, java.lang.Class, java.lang.String), use([Ljava.lang.Object;), use(java.lang.Class, groovy.lang.Closure), wait(), grep()


Has anyone tried something like this before?

Solution

GitHub plugin doesn't pass payload data to any variables available from inside the pipeline.

Both Jenkins tracker and GitHub plugin project have a number of open and cancelled feature requests requesting this, for instance, https://issues.jenkins-ci.org/browse/JENKINS-24291.

Context

StackExchange DevOps Q#8306, answer score: 2

Revisions (0)

No revisions yet.