Drae Gen
Drae Gen

Reputation: 3

How do I access the payload from a generic webhook in my Jenkinsfile?

I have a multibranch job using a generic webhook and I want to access the JSON payload the Jenkins receives. I unfortunately cannot seem to access it, I cannot define parameters for the multibranch job and I am at a loss.

I would like to determine the cause of the trigger, whether it be from a pull request, a push, a commit, etc. Multibranch pipelines don't allow for me to specify any variables in Jenkins, so I'm a bit confused.

Upvotes: 0

Views: 4301

Answers (2)

sri koganti
sri koganti

Reputation: 1

You can access the payload by configuring build triggers in the configure section of the jenkins job.enter image description here

Upvotes: 0

Tomas Bjerre
Tomas Bjerre

Reputation: 3500

Configure a JSONPath variable with the JSONPath $ and it will be resolved to the entire received JSON.

See also: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/jsonpath.feature

And to do this in a multibranch pipeline, your pipeline can look something like this:

 properties([
  pipelineTriggers([
   [$class: 'GenericTrigger',
    genericVariables: [
     [key: 'everything', value: '$']
    ],
   ...
   ]
  ])
 ])

The readme has complete examples on how to use it with Multibranch.

Upvotes: 3

Related Questions