POST钩子在Bitbucket上 [英] POST hook on Bitbucket

查看:196
本文介绍了POST钩子在Bitbucket上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在私人Jenkins的bitbucket中使用POST URL?



我一直在遇到 bitbucket 和他们的提交后。

描述:



http://用户名:password@myjenkins.instance/ job / myproject / build?token = mytoken



我有一个jenkins实例,我想在触发某些存储库时触发。由于jenkins可从外部(万维网)访问,因此通过典型的用户/密码系统进行保护。

使用Github时,我可以直接在URL中定义用户名和密码。在检查nginx日志时,显然github能够将该url转换为登录用户。 Bitbucket不是。



以下是一些显示问题的nginx日志。



Bitbucket发布日志:

  -   - POST / job / myproject / build?token = mytoken HTTP / 1.1403 216 - Bitbucket.org

有趣的部分是403错误。 Acces拒绝。



针对Github帖子的相同日志

   -  github  - POST / job / myproject / build?token = mytoken HTTP / 1.1302 0 -  - 

当日志显示时,github是我创建的用户的名称,具有启动构建的良好权限。

我可以做些什么来启用post hook?

解决方案

如果你想让BitBucket触发一个Jenkins作业,在你的repo提交后执行,你有两个选择: p>


  • 使用POST钩子

  • 使用Jenkins钩子



两者都使用Jenkins API触发作业。



对于POST钩子,基本上需要将url构建为这:

  https:// USER:APITOKEN @ JENKINS_URL / job / JOBNAME / build?token = TOKEN 

其中:


  • USER :是将触发作业的Jenkins用户

  • APITOKEN :是与该用户关联的令牌,允许使用API ,您可以从Jenkins的用户配置页面获取它

  • JENKINS_URL :jenkins服务器的URL

  • 强> JOBNAME :作业名称

  • TOKEN :与第您必须将其添加到作业配置页面中(启用远程触发器)



关于这一点很酷的事情是,您可以检查如果它只是从控制台使用curl。



另外请注意,url中没有密码,您有API TOKEN,这是为了避免发布您的用户和密码。
如果您在Jenkins服务器中拥有管理员权限,则可以采取其他一些措施来提高安全性,创建仅具有读取和构建作业的访问权限的新用户,并仅将其用于此目的。因此,您不必发布自己的用户和令牌,这可能具有管理员权限。



Jenkins挂钩的工作方式相同,为您创建相同的URL,但您没有机会测试它(例如,使用curl)。

这是基于以下文档:



希望它有帮助。



Ger


How to use the POST url in bitbucket on private Jenkins?

I have been experiencing problems with bitbucket and their post commit.

Description :

http://username:password@myjenkins.instance/job/myproject/build?token=mytoken

I have a jenkins instance I would like to trigger on push on certain repositories. Since the jenkins is accessible from the outside (the world wide web), it is protected through the typical user/password system.

When working with Github, I can define the usename and password directly in the URL. When checking the nginx logs, it is clear that github is able to convert that url to login the user. Bitbucket is not.

Here are some nginx logs showing the problem.

Bitbucket post logs :

- - "POST /job/myproject/build?token=mytoken HTTP/1.1" 403 216 "-" "Bitbucket.org"

The interesting part is the 403 error. Acces refused.

Same logs for the Github post hook:

- github - "POST /job/myproject/build?token=mytoken HTTP/1.1" 302 0 "-" "-"

AS the logs show, github is the name of the user I created with the good rights for launching builds.

What can I possibly do to enable the post hook?

解决方案

If you want to make BitBucket trigger a Jenkins job execution after a commit in your repo, you have two options:

  • Use the POST hook
  • Use the Jenkins hook

Both using the Jenkins API to trigger the job.

For the POST hook, you basically need to build the url as this:

https://USER:APITOKEN@JENKINS_URL/job/JOBNAME/build?token=TOKEN

where:

  • USER: is the Jenkins user that will trigger the job
  • APITOKEN: is a token associated to that user to allow the use of the API, you can get it from the user configuration page in Jenkins
  • JENKINS_URL: the url of your jenkins server
  • JOBNAME: the name of the job
  • TOKEN: the token associated to the job, you must add it in the job configuration page (enable remote triggers)

The cool thing about this is that you can check if it works just using curl from the console.

Also note there is no password in the url, you have the API TOKEN instead, this is to avoid publishing your user and password. Something else you can do to improve security a little bit, if you have admin rights in the Jenkins server, create a new user with just access rights to read and build jobs, and use it only for this. So you don't have to publish your own user and token, which may have admin rights.

The Jenkins hook works the same way, building the same URL for you, but you don't have the chance to test it (for instance, using curl).

This is based on these documents:

Hope it helps.

Ger

这篇关于POST钩子在Bitbucket上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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