简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM