简体   繁体   English

当 github 帐户使用 2 因子身份验证时,是否可以将 Jenkins Webhooks 与 Github 一起使用

[英]Is it possible to use Jenkins Webhooks with Github when the github account uses 2 factor auth

I am using the latest docker image for jenkins (jenkins/jenkins:lts JENKINS_VERSION 2.208).我正在为 jenkins 使用最新的 docker 镜像(jenkins/jenkins:lts JENKINS_VERSION 2.208)。 I have started the container, configured jenkins and can manually build against a public repo.我已经启动了容器,配置了 jenkins,并且可以针对公共存储库手动构建。 However, on my github account I have 2FA, which must remain.但是,在我的 github 帐户上,我有 2FA,必须保留。 I have created a personal access token in Github, and used this in my jenkins config for github server section.我在 Github 中创建了一个个人访问令牌,并在我的 jenkins 配置中用于 github 服务器部分。 I have validated that the connection is working by pressing the test connection link (I added secret text that used my personal access token from github):我已经通过按下测试连接链接来验证连接是否正常(我添加了使用来自 github 的个人访问令牌的秘密文本): Jenkins Github 服务器设置

In Github, I have wekhook settings with the IP address for where jenkins is hosted (the IP for the docker container) follwed by github-webhook (I have also tried using a dns mapped address for jenkins as well, eg, http://jenkins-local/github-webhook ), content type is application/json:在 Github 中,我有 wekhook 设置,其中包含 jenkins 托管位置的 IP 地址(docker 容器的 IP),然后是 github-webhook(我也尝试使用 jenkins 的 dns 映射地址,例如http:// jenkins-local/github-webhook ),内容类型为 application/json: Github 网络钩子设置 . .

I have github polling enabled in jenkins as well, however, it does not work on push requests to the repo.我也在 jenkins 中启用了 github 轮询,但是,它不适用于对 repo 的推送请求。 I see failure logs in Github within the webhooks section, this increases each time I make a push (the request keeps failing).我在 webhooks 部分的 Github 中看到失败日志,每次我进行推送时都会增加(请求不断失败)。 I have searched wide across the internet and found documentation of suggestions on what to do, including this link here: securing your webhooks , but nothing is giving me the desired polling effect when a push is initiated and a build triggered.我在互联网上进行了广泛搜索,并找到了有关如何操作的建议文档,包括此处的链接:保护您的 webhooks ,但是当发起推送并触发构建时,没有任何内容给我所需的轮询效果。 So my question is, is it possible to use 2FA and github webhooks?所以我的问题是,是否可以使用 2FA 和 github webhooks? If it is possible, then what are the exact steps to do it?如果可能,那么具体的步骤是什么?

If you have 2FA enabled, you cannot authenticate with a login/pass from your tools anymore.如果您启用了 2FA,您将无法再使用工具中的登录名/密码进行身份验证。 You need to create a token that you will use in place of your password.您需要创建一个令牌来代替您的密码。

The official documentation should get you there in almost no time. 官方文档应该很快就能让你到达那里。

In the end the solution was to download ngrok.最后的解决办法是下载ngrok。 The IP address that the I had previously tried and the dns mapped address were not publicly available.我之前尝试过的 IP 地址和 dns 映射地址不是公开可用的。 I tried using my public ip address as well, but that also didn't work.我也尝试使用我的公共 IP 地址,但这也不起作用。 In the end, downloading ngrok gave me a publicly accessible ip address (the address will look like the following: http://1212344a.ngrok.io ).最后,下载 ngrok 给了我一个可公开访问的 ip 地址(地址将如下所示: http : //1212344a.ngrok.io )。 If you also plan to use ngrok then ensure that when you start it from the command line/terminal that you also pass the same port for the application that is running locally, if one is required.如果您还计划使用 ngrok,请确保当您从命令行/终端启动它时,如果需要,您还为本地运行的应用程序传递相同的端口。 Next, in github - settings - webhooks set the payload url to the url that ngrok provides in the terminal output, but also append /github-webhook/ on to the end of the address to complete the payload url (in my case this was http://1212344a.ngrok.io/github-webhook/ as the full payload url).接下来,在 github - settings - webhooks 中将有效负载 url 设置为 ngrok 在终端输出中提供的 url,但还将 /github-webhook/ 附加到地址末尾以完成有效负载 url(在我的情况下,这是http ://1212344a.ngrok.io/github-webhook/作为完整的有效负载 URL)。

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

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