首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GitHub网络钩子不能连接到VPN内的Jenkins?

GitHub网络钩子不能连接到VPN内的Jenkins?
EN

Stack Overflow用户
提问于 2021-03-19 08:54:23
回答 2查看 1.1K关注 0票数 6

我正在使用Jenkins和GitHub企业建立持续集成。

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

  • Jenkins使用SSH公钥/私钥来验证和克隆GitHub repos。
  • Jenkins运行在我公司VPN网络中的Linux服务器上。

我的下一步是配置Jenkins/GitHub,这样每个git push到GitHub都会触发一个Jenkins构建作业。我已经在GitHub上设置了post提交webhook,并在我的Jenkins项目中启用了GitHub hook trigger for GITScm polling复选框。

但是,GitHub无法连接到Jenkins。

这是日志:

代码语言:javascript
运行
复制
We couldn’t deliver this payload: failed to connect

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

有什么问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-14 10:54:55

问题就在于github无法访问您的内部网络。

Jenkins社区博客上的一篇文章中,作者建议使用斯密 (在ISC许可下发布)进行网络钩子转发。

票数 3
EN

Stack Overflow用户

发布于 2022-11-02 08:58:22

如果使用smee将webhooks从GitHub传递给您的VPNed Jenkins (您设置了Github将事件发送给smee.io,而不是使用Smee客户机检索事件并在Jenknins上内部使用它们),下面是设置它的快速方法。

  1. 转到Smee.io,给自己找一个“通道”,写下你得到的网址(例如https://smee.io/Wua8D46nBvJ63nPP)。
  2. 在你的詹金斯上安装Smee:sudo npm install --global smee-client
  3. 配置内部转发:smee -u https://smee.io/Wua8D46nBvJ63nPP --path /github-webhook/ --port 8080
  4. 转到您的GitHub存储库:Settings->Webhooks->Add webhook,并将URL粘贴到"Payload“下,选择内容类型"application/json”。
  5. 将Smee设置为在Jenkins上作为服务运行,以便在启动时启动。您需要两个文件:
  • Init脚本/etc/init.d/smee
  • systemctl服务描述文件/etc/systemd/system/smee.service

/etc/init.d/smee

代码语言:javascript
运行
复制
#! /bin/sh
### BEGIN INIT INFO
# Provides:          smee
# Required-Start:    $all
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      
# Short-Description: Start SMEE daemon at boot time
# Description:       Forwards GitHub webhook notifications to Jenkins.
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/smee
PIDFILE=/var/run/smee.pid

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
 log_daemon_msg "Starting smee" "smee"
 start_daemon -p $PIDFILE $DAEMON
 log_end_msg $?
    ;;
  stop)
 log_daemon_msg "Stopping smee" "smee"
 killproc -p $PIDFILE $DAEMON
 log_end_msg $?
    ;;  
  force-reload|restart)
    $0 stop
    $0 start
    ;;
  status)
    status_of_proc -p $PIDFILE $DAEMON atd && exit 0 || exit $?
    ;;
  *)
    echo "Usage: /etc/init.d/smee {start|stop|restart|force-reload|status}"
    exit 1
    ;;
esac

exit 0

/etc/systemd/system/smee.service

代码语言:javascript
运行
复制
[Unit]
Description=smee.io webhook delivery from GitHub
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=jenkins
ExecStart=/usr/bin/smee -u https://smee.io/Wua8D46nBvJ63nPP --path /jenkins/github-webhook/ --port 8080

[Install]
WantedBy=multi-user.target

启动服务:sudo /etc/init.d/smee start

检查状态:sudo /etc/init.d/smee status

现在应该将存储库中的通知发送给Jenkins,Jenkins应该能够看到和处理它们。要快速检查Jenkins是否处理任何Smee组件,请打开“仪表板->系统日志”并搜索"smee“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66705115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档