从jenkins的web钩子检索post数据 [英] retrieving post data from web hook in jenkins

查看:805
本文介绍了从jenkins的web钩子检索post数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gitlab,我想要在每个项目创建时触发一个系统钩子。我添加了钩子与以下jenkins api调用(我使用的jenkins插件,这就是为什么api看起来不同)。



http: // myip:8081 / buildByToken / buildWithParameters?job = testHook& token = hook



这是启动jenkins作业,在我的jenkins作业中获取通过钩子发送的帖子数据。



以下是gitlab使用此钩子作为帖子数据发送的示例。

  {
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,
} / code>

有没有办法检索与webook一起发送的jenkins中的发布数据?



/github.com/elvanja/jenkins-gitlab-hook-plugin#build-now-hookrel =nofollow> https://github.com/elvanja/jenkins-gitlab-hook-plugin#build-now-hook



使用 http: //your-jenkins-server.com/gitlab/build_now ,您可以访问所有有效负载变量,如文档中的示例。您的构建需要参数化,并且您需要访问的所有变量都需要声明。然后,你将有一个env变量可用,如$ {USER_NAME}



然而,如果你想使用/ gitlab / notify_commit, ,有效载荷数据将不工作,因为触发器和构建之间的差距(我说的轮询过程)。



我相信你的/ buildByToken / buildWithParameters ,因为它的一个build_now喜欢,将有有效载荷。使用GitLabHookPlugin,您将具有确定的参数。



Marco


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?

解决方案

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

这篇关于从jenkins的web钩子检索post数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆