问题
I am using gitlab and I want to fire a system hook whenever a project is created. I have added the hook with the following jenkins api call(I am using a jenkins plugin that is why the api looks different).
http://myip:8081/buildByToken/buildWithParameters?job=testHook&token=hook
this is starting the jenkins job but I am unable to get the post data sent by the hook in my jenkins job.
the following is an example of what gitlab sends as post data with this hook.
{
"created_at": "2012-07-21T07:30:54Z",
"event_name": "project_create",
"name": "StoreCloud",
"owner_email": "johnsmith@gmail.com",
"owner_name": "John Smith",
"path": "stormcloud",
"path_with_namespace": "jsmith/stormcloud",
"project_id": 74,
"project_visibility": "private",
}
is there a way to retrieve post data in jenkins that is sent with the webook?
回答1:
There is a plugin specific for Jenkins and Gitlab integration.
https://github.com/elvanja/jenkins-gitlab-hook-plugin#build-now-hook
By using http://your-jenkins-server.com/gitlab/build_now, you can have access to all payload variables, like the examples in documentation. Your build needs to be parameterized, and all variables you want to have access need to be declared. Then, you will have a env variable available, like ${USER_NAME}
However, if you want to use /gitlab/notify_commit, which has a lot of more cool possibilities, payload data will not work, because of the gap between the trigger and the build (i am talking about the poll process).
I believe that your /buildByToken/buildWithParameters, since its a build_now like, will have the payload. Using GitLabHookPlugin, you will have the parameters for sure.
Marco
来源:https://stackoverflow.com/questions/25568936/retrieving-post-data-from-web-hook-in-jenkins