简体   繁体   English

如何为内部服务器配置GitHub Web Hook for Jenkins?

[英]How to configure GitHub Web Hook for Jenkins for inhouse server?

I have a Jenkins instance on an in-house server.我在内部服务器上有一个Jenkins实例。 There is no public IP or domain name for the server at this time.此时服务器没有公共 IP 或域名。 Can I still configure a webhook?我还可以配置 webhook 吗? I don't see how GitHub would ever be able to see and send any kind of message to this server.我看不出 GitHub 如何能够看到并向该服务器发送任何类型的消息。 Do I need to set up a port forward on my top-level router?我需要在顶级路由器上设置端口转发吗? Is there a secure way to approach this?有没有安全的方法来解决这个问题?

I'm following the steps in this tutorial :我正在按照本教程中的步骤操作:

Open the “Webhooks & Services” tab -> choose “Configure Services” -> find the Jenkins (GitHub plugin option) and fill it in with a similar URL to the following: http://<Name of Jenkins server>:8080/github-webhook/打开“Webhooks & Services”选项卡 -> 选择“Configure Services” -> 找到 Jenkins(GitHub 插件选项)并填写类似 URL 的内容: http://<Name of Jenkins server>:8080/github-webhook/

You can check your current public ip by browsing to www.whatismyip.com.您可以通过浏览 www.whatismyip.com 来查看您当前的公共 IP。 then you can configure the webhook to your public ip.然后您可以将 webhook 配置为您的公共 ip。 since this address is not really you ip address, but instead the router address - you will have to configure port forwarding on that router back to your Jenkins host.因为这个地址实际上不是你的 IP 地址,而是路由器地址 - 你必须在该路由器上配置端口转发回到你的 Jenkins 主机。 The main problem is that your ip address probably get changed when you reconnects your router - you can use a dynamic dns to have a dns record points to your current ip address.主要问题是当您重新连接路由器时,您的 ip 地址可能会更改 - 您可以使用动态 dns 将 dns 记录指向您当前的 ip 地址。

From chenchuk 's answer来自chenchuk回答

you will have to configure port forwarding on that router back to your Jenkins host您必须将该路由器上的端口转发配置回您的 Jenkins 主机

There is also an alternative approach (in Nov. 2022, 6 years later)还有一种替代方法(2022 年 11 月,6 年后)

Webhook forwarding in the GitHub CLI (public beta) (Nov. 2022) GitHub CLI 中的 Webhook 转发(公测) (2022 年 11 月)

We've launched a limited public beta of a new feature in the GitHub CLI: webhook forwarding.我们在 GitHub CLI 中推出了一项新功能的有限公开测试版:webhook 转发。

Webhook forwarding makes it easy to test your webhooks integration in your local environment without having to worry about port forwarding . Webhook 转发使您可以轻松地在本地环境中测试您的webhooks集成,而不必担心端口转发

All it takes to start receiving webhooks locally is one simple command:开始在本地接收 webhooks 只需要一个简单的命令:

gh webhook forward --repo monalisa/hello-world --events issues,pull_request --url http://localhost:4000/webhooks

With webhook forwarding, you can iterate quickly on your integration without having to deploy your code to a test environment.借助 Webhook 转发,您可以快速迭代集成,而无需将代码部署到测试环境。

For more details on this new feature, head over to the docs – see "Receiving webhooks with the GitHub CLI" .有关此新功能的更多详细信息,请转到文档 – 请参阅“使用 GitHub CLI 接收 webhook”

To request access to the beta program, post in our GitHub Community discussion .要请求访问测试程序,请在我们的GitHub 社区讨论中发帖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM