Reputation: 1536
I'm a newbie in Jenkins. I followed this help to implement Jenkins, Github and Webhook.
However, I'm stuck in this problem. I want to get the payload parameters in Jenkins to check information such as changes, actions...from payload json.
I wrote some script to test. ACTION
and $payload
always returns empty
# !/bin/bash
ACTION=`echo $payload | php -r '$data = file_get_contents("php://stdin"); $json = json_decode($data, true); echo $json["action"];'`
I read some tutorials but unsuccessfully.
Upvotes: 1
Views: 10838
Reputation: 316
There are few steps that you should follow:
Configure a web-hook in GitHub by which you will start communicating with Jenkins. This can be easily by going to your GitHub repository --> Setting --> Web-hooks.
Make the entry for content-type as application/x-www-form-encoded
.
Select the event as Push event.
Create a String parameter in Jenkins Server by the name of payload
.
Following Step 3 GitHub would be able to wrap the content in this variable and send it to Jenkins.
In Jenkins you can then read $payload variable when your build is kicked off.
Parse the JSON using library of your choice
Upvotes: 4
Reputation: 3500
Easier way of doing this, without an extra library for parsing JSON, would be using the Generic Webhook Trigger Plugin in Jenkins.
It can resolve any value from the JSON using JSONPath and assign it to variables available in the build.
Upvotes: 3