我有一个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"> gitlab )和以前在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 (gitlab) 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上,因此无法修改此选项.
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 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配置
发布评论