GitHub webhook 无法在 VPN 内连接到 Jenkins?

Dan*_*jel 7 continuous-integration github jenkins github-webhook

我正在使用 Jenkins 和 GitHub Enterprise 设置持续集成。

\n

到目前为止,我已经能够轻松创建 Jenkins 项目并定期运行作业。

\n
    \n
  • Jenkins 使用 SSH 公钥/私钥来验证和克隆 GitHub 存储库。
  • \n
  • Jenkins 在我公司 VPN 网络内的 Linux 服务器上运行。
  • \n
\n

我的下一步是配置 Jenkins/GitHub,以便每个git pushGitHub 都会触发 Jenkins 构建作业。我已在 GitHub 上设置了提交后 Webhook,并GitHub hook trigger for GITScm polling在我的 Jenkins 项目中启用了该复选框。

\n

但是,GitHub 无法连接到 Jenkins。

\n

这是日志:

\n
We couldn\xe2\x80\x99t deliver this payload: failed to connect\n\n{\n  "zen": "Design for failure.",\n  "hook_id": 287451636,\n  "hook": {\n    "type": "Repository",\n    "id": 287451636,\n    "name": "web",\n    "active": true,\n    "events": [\n      "push"\n    ],\n    "config": {\n      "content_type": "json",\n      "insecure_ssl": "0",\n      "url": "http://1.2.3.4/jenkins/github-webhook/"\n    },\n    "updated_at": "2021-03-19T07:45:12Z",\n    "created_at": "2021-03-19T07:45:12Z",\n    "url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636",\n    "test_url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636/test",\n    "ping_url": "https://api.github.com/repos/mycompany/my_repo/hooks/287451636/pings",\n    "last_response": {\n      "code": null,\n      "status": "unused",\n      "message": null\n    }\n  },\n  "repository": {\n    "id": 347030450,\n    "node_id": "MDEwOlJlcG9zaXRvcnkzNDcwMzA0NTA=",\n    "name": "my_repo",\n    "full_name": "mycompany/my_repo",\n    "private": true,\n    "owner": {\n      "login": "mycompany",\n      "id": 11980925,\n      "node_id": "MDEyOk9yZ2FuaXphdGlvbjExOTgwOTI1",\n      "avatar_url": "https://avatars.githubusercontent.com/u/11980925?v=4",\n      "gravatar_id": "",\n      "url": "https://api.github.com/users/mycompany",\n      "html_url": "https://github.com/mycompany",\n      "followers_url": "https://api.github.com/users/mycompany/followers",\n      "following_url": "https://api.github.com/users/mycompany/following{/other_user}",\n      "gists_url": "https://api.github.com/users/mycompany/gists{/gist_id}",\n      "starred_url": "https://api.github.com/users/mycompany/starred{/owner}{/repo}",\n      "subscriptions_url": "https://api.github.com/users/mycompany/subscriptions",\n      "organizations_url": "https://api.github.com/users/mycompany/orgs",\n      "repos_url": "https://api.github.com/users/mycompany/repos",\n      "events_url": "https://api.github.com/users/mycompany/events{/privacy}",\n      "received_events_url": "https://api.github.com/users/mycompany/received_events",\n      "type": "Organization",\n      "site_admin": false\n    },\n    "html_url": "https://github.com/mycompany/my_repo",\n    "description": "My test repo.",\n    "fork": false,\n    "url": "https://api.github.com/repos/mycompany/my_repo",\n    "forks_url": "https://api.github.com/repos/mycompany/my_repo/forks",\n    "keys_url": "https://api.github.com/repos/mycompany/my_repo/keys{/key_id}",\n    "collaborators_url": "https://api.github.com/repos/mycompany/my_repo/collaborators{/collaborator}",\n    "teams_url": "https://api.github.com/repos/mycompany/my_repo/teams",\n    "hooks_url": "https://api.github.com/repos/mycompany/my_repo/hooks",\n    "issue_events_url": "https://api.github.com/repos/mycompany/my_repo/issues/events{/number}",\n    "events_url": "https://api.github.com/repos/mycompany/my_repo/events",\n    "assignees_url": "https://api.github.com/repos/mycompany/my_repo/assignees{/user}",\n    "branches_url": "https://api.github.com/repos/mycompany/my_repo/branches{/branch}",\n    "tags_url": "https://api.github.com/repos/mycompany/my_repo/tags",\n    "blobs_url": "https://api.github.com/repos/mycompany/my_repo/git/blobs{/sha}",\n    "git_tags_url": "https://api.github.com/repos/mycompany/my_repo/git/tags{/sha}",\n    "git_refs_url": "https://api.github.com/repos/mycompany/my_repo/git/refs{/sha}",\n    "trees_url": "https://api.github.com/repos/mycompany/my_repo/git/trees{/sha}",\n    "statuses_url": "https://api.github.com/repos/mycompany/my_repo/statuses/{sha}",\n    "languages_url": "https://api.github.com/repos/mycompany/my_repo/languages",\n    "stargazers_url": "https://api.github.com/repos/mycompany/my_repo/stargazers",\n    "contributors_url": "https://api.github.com/repos/mycompany/my_repo/contributors",\n    "subscribers_url": "https://api.github.com/repos/mycompany/my_repo/subscribers",\n    "subscription_url": "https://api.github.com/repos/mycompany/my_repo/subscription",\n    "commits_url": "https://api.github.com/repos/mycompany/my_repo/commits{/sha}",\n    "git_commits_url": "https://api.github.com/repos/mycompany/my_repo/git/commits{/sha}",\n    "comments_url": "https://api.github.com/repos/mycompany/my_repo/comments{/number}",\n    "issue_comment_url": "https://api.github.com/repos/mycompany/my_repo/issues/comments{/number}",\n    "contents_url": "https://api.github.com/repos/mycompany/my_repo/contents/{+path}",\n    "compare_url": "https://api.github.com/repos/mycompany/my_repo/compare/{base}...{head}",\n    "merges_url": "https://api.github.com/repos/mycompany/my_repo/merges",\n    "archive_url": "https://api.github.com/repos/mycompany/my_repo/{archive_format}{/ref}",\n    "downloads_url": "https://api.github.com/repos/mycompany/my_repo/downloads",\n    "issues_url": "https://api.github.com/repos/mycompany/my_repo/issues{/number}",\n    "pulls_url": "https://api.github.com/repos/mycompany/my_repo/pulls{/number}",\n    "milestones_url": "https://api.github.com/repos/mycompany/my_repo/milestones{/number}",\n    "notifications_url": "https://api.github.com/repos/mycompany/my_repo/notifications{?since,all,participating}",\n    "labels_url": "https://api.github.com/repos/mycompany/my_repo/labels{/name}",\n    "releases_url": "https://api.github.com/repos/mycompany/my_repo/releases{/id}",\n    "deployments_url": "https://api.github.com/repos/mycompany/my_repo/deployments",\n    "created_at": "2021-03-12T10:40:44Z",\n    "updated_at": "2021-03-18T13:59:52Z",\n    "pushed_at": "2021-03-18T13:59:49Z",\n    "git_url": "git://github.com/mycompany/my_repo.git",\n    "ssh_url": "git@github.com:mycompany/my_repo.git",\n    "clone_url": "https://github.com/mycompany/my_repo.git",\n    "svn_url": "https://github.com/mycompany/my_repo",\n    "homepage": null,\n    "size": 3,\n    "stargazers_count": 0,\n    "watchers_count": 0,\n    "language": "Makefile",\n    "has_issues": true,\n    "has_projects": true,\n    "has_downloads": true,\n    "has_wiki": true,\n    "has_pages": false,\n    "forks_count": 0,\n    "mirror_url": null,\n    "archived": false,\n    "disabled": false,\n    "open_issues_count": 0,\n    "license": null,\n    "forks": 0,\n    "open_issues": 0,\n    "watchers": 0,\n    "default_branch": "main"\n  },\n  "sender": {\n    "login": "MyLogin",\n    "id": 63738097,\n    "node_id": "MDQ6VXNlcjYzNzM4MDk3",\n    "avatar_url": "https://avatars.githubusercontent.com/u/13818097?v=4",\n    "gravatar_id": "",\n    "url": "https://api.github.com/users/MyLogin",\n    "html_url": "https://github.com/MyLogin",\n    "followers_url": "https://api.github.com/users/MyLogin/followers",\n    "following_url": "https://api.github.com/users/MyLogin/following{/other_user}",\n    "gists_url": "https://api.github.com/users/MyLogin/gists{/gist_id}",\n    "starred_url": "https://api.github.com/users/MyLogin/starred{/owner}{/repo}",\n    "subscriptions_url": "https://api.github.com/users/MyLogin/subscriptions",\n    "organizations_url": "https://api.github.com/users/MyLogin/orgs",\n    "repos_url": "https://api.github.com/users/MyLogin/repos",\n    "events_url": "https://api.github.com/users/MyLogin/events{/privacy}",\n    "received_events_url": "https://api.github.com/users/MyLogin/received_events",\n    "type": "User",\n    "site_admin": false\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

可能是什么问题呢?

\n

Ser*_*gey 4

那么问题正是因为github无法访问你的内部网络。

Jenkins 社区博客中有一篇文章,作者建议使用smee(在 ISC 许可证下发布)进行 webhooks 转发。