fuzzi
fuzzi

Reputation: 2277

How to read in a Jenkins Web Hook post request body?

I have an application that is triggering a Jenkins job via a Web Hook. The web hook makes a POST request that contains data I need to use within the Jenkins Job - different actions will be taken depending on the request body.

How do I pass this request body to my script? - Is is accessible from the Build Actions?

I haven't written the script yet, but it may be in Bash, or Python.

Is the Generic Webhook Trigger Plugin (https://wiki.jenkins.io/display/JENKINS/Generic+Webhook+Trigger+Plugin) the way to go?

Any help on this will be greatly appreciated!

Upvotes: 4

Views: 4882

Answers (1)

VonC
VonC

Reputation: 1323953

Is the Generic Webhook Trigger Plugin the way to go?

Yes, considering it can extract from a response body in JSON any value you want, as illustrated by this issue.

  genericTrigger {
   genericVariables {
    genericVariable {
     key("VARIABLE_FROM_POST")
     value("\$.something")
     expressionType("JSONPath") //Optional, defaults to JSONPath
     regexpFilter("") //Optional, defaults to empty string
     defaultValue("") //Optional, defaults to empty string
    }
   }
   ...

That would extract from the JSON response body the "something" element value.

And/or you can get back the all JSON payload.

If you specify the JSONPath as just $ then that should evaluate to all json.

Upvotes: 4

Related Questions