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

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

我正在为 jenkins 使用最新的 docker 图像 (jenkins/jenkins:lts JENKINS_VERSION 2.208)。我已经启动了容器,配置了 jenkins 并且可以针对 public 存储库手动构建。但是,在我的 github 帐户上,我有 2FA,必须保留。我在 Github 中创建了一个个人访问令牌,并在我的 github 服务器部分的 jenkins 配置中使用了它。我已通过按测试连接 link 验证连接是否正常工作(我添加了使用来自 github 的个人访问令牌的秘密文本):

在 Github 中,我有 wekhook 设置,其中包含托管 jenkins 的 IP 地址(docker 容器的 IP),然后是 github-webhook(我也有也尝试为 jenkins 使用 dns 映射地址,例如 http://jenkins-local/github-webhook), content type is application/json:.

我也在 jenkins 中启用了 github 轮询,但是,它不适用于对 repo 的推送请求。我在 webhooks 部分的 Github 中看到失败日志,每次我进行推送时都会增加(请求一直失败)。我在 Internet 上进行了广泛搜索,找到了有关如何操作的建议文档,包括此处的 link:securing your webhooks,但在启动推送和触发构建时,没有任何东西给我所需的轮询效果.所以我的问题是,是否可以使用 2FA 和 github webhooks?如果可以的话,具体步骤是什么?

如果启用了 2FA,则无法再使用工具中的 login/pass 进行身份验证。您需要创建一个令牌来代替您的密码。

official documentation 几乎可以立即将您送达。

最终解决方案是下载 ngrok。我之前尝试过的 IP 地址和 dns 映射地址 public 不可用。我也尝试使用我的 public ip 地址,但这也没有用。最后,下载 ngrok 给了我一个 public 可访问的 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. 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/ 作为完整的有效负载 url)。