使用Gitlab进行Webhook配置 [英] Webhook configuration with Gitlab

查看:693
本文介绍了使用Gitlab进行Webhook配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jenkins管道项目,我想在每次推送到托管代码的Gitlab存储库时触发一个构建.

I have a Jenkins pipeline project and I would like to trigger a build every time a push to the Gitlab repository where the code is hosted is performed.

在Jenkins上,我安装了Gitlab插件和Git插件,并通过添加Gitlab主机URL(配置系统). rel ="nofollow noreferrer"> https://gitlab.com )和以前在Gitlab上生成的Gitlab API令牌:如果执行测试连接,一切正常,如预期.

On Jenkins I have installed the Gitlab plugin and the Git plugin and I have configured the Gitlab section (Manage Jenkins -> Configure System) by adding the Gitlab host URL (https://gitlab.com) and the Gitlab API token previously generated on Gitlab: if I perform a test connection, everything is OK, as expected.

问题出在Gitlab上:我转到设置"->集成",然后尝试通过添加在项目配置中找到的Jenkins项目URL来配置Webhook(以下突出显示):

The problem is on Gitlab: I go to Settings -> Integrations and I try to configure a webhook by adding the Jenkins project URL that I have found in the project configuration (highlighted below):

但是有一个问题:似乎不允许从Gitlab向本地主机发出请求.

But there is a problem: it seems that requests to localhost from Gitlab are not allowed.

为了避免这个问题,似乎有必要激活一个选项(允许从挂钩和服务到本地网络的请求),但是只有当我自己管理一个Gitlab服务器时,此选项才可用.相反,我的项目托管在gitlab.com上,因此无法修改此选项.

It seems that to avoid this problem is necessary to activate an option (Allow requests to the local network from hooks and services), but this option is available only if I have a Gitlab server managed by myself. Instead, my project is hosted on gitlab.com and so this option cannot be modified.

在我的情况下,是否有任何变通办法或替代解决方案来配置Webhook?

There is any workaround or alternative solution to configure a webhook in my case?

推荐答案

如果jenkins正在运行

If jenkins is running

  • 公司防火墙后面,
  • 或在笔记本电脑上
  • 或在互联网上无法通过永久URL提供的任何计算机上(更确切地说,在您要连接的gitlab实例中)

-很可能是这种情况,那么您需要使用相反的方法:jenkins定期轮询git存储库.然后,您可以选择轮询的频率(以类似于cron的方式).

- which is very likely the case, then you need to use the opposite approach: jenkins periodically polling git repository. You can then choose how frequently will the polling happen (in cron-like manner).

这也是jenkins提供的标准方法,即不需要gitlab插件,只需提供正确的凭据即可.

This is also the standard approach offered by jenkins, i.e. this does not require gitlab plugin, just correct credentials.

缺点是,它定期连接可能消耗一些数据的公共gitlab实例;但这可能微不足道.

The downside is, it regularly connects the public gitlab instance which may consume some data; but that is probably insignificant.

这篇关于使用Gitlab进行Webhook配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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