推送到不同的存储库时自动触发 Travis? [英] Automatically triggering Travis on push to a different repository?

查看:24
本文介绍了推送到不同的存储库时自动触发 Travis?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在每次推送到存储库 Y 时触发存储库 X 的 Travis CI 构建?具体来说,我希望我的构建在每次推送到 http://github.com/tensorflow/tensorflow

Is there a way to trigger Travis CI build for repository X each time there's a push to repository Y? Specifically, I want my builds to start each time there's a push to http://github.com/tensorflow/tensorflow

推荐答案

好问题!以下是我能想到的一些解决方案:

Good question! Here are some solutions that I could think of:

如果您拥有 repo 的管理员权限(或知道有管理员权限的人),您可以创建一个订阅 push 事件的网络钩子,并在触发时启动使用 Travis API 在 Travis CI 上构建.

If you have admin privileges on the repo (or know someone who does), you could create a webhook that subscribes to the push event and when triggered, start a build on Travis CI using the Travis API.

这将需要:

  1. http://github.com 上创建一个新的 GitHub 网络钩子/tensorflow/tensorflow/settings/hooks/new.当然,根据您的需要自定义设置,但根据我掌握的信息,我建议使用 application/json 内容类型,并且仅让 GitHub 使用 push事件.

  1. Creating a new GitHub webhook over on http://github.com/tensorflow/tensorflow/settings/hooks/new. While of course, customizing the settings as you see fit, but with the information I have, I recommend using the application/json content type and only have GitHub trigger the webhook with the push event.

编写一个需要来自 GitHub 的 HTTP POST 有效负载的小型 Web 应用程序,并使用 Travis CI 的 API 开始构建.此网络应用可以用任何语言编写,但必须部署到始终处于唤醒状态和监听状态的地方(以防止丢失构建).

Write a small web app expecting the HTTP POST payloads from GitHub and start builds using Travis CI's API. This web app can be written in any language but it must be deployed to somewhere that is always awake and listening (to prevent missing builds).

这是我的例子.

post "/push-webhook" do
  uri = URI.parse("https://api.travis-ci.org/repo/your-org/your-repo/requests")

  request = Net::HTTP::Get.new(uri.request_uri)
  request["Content-Type"] = "application/json"
  request["Accept"] = "application/json"
  request["Travis-API-Version"] = "3"
  request["Authorization"] = "token your-token"

  body = { "request" => { "branch" => "master" } }
  request.body = body.to_json

  response = http.request(request)
end

  1. 瞧!一旦部署了这个 Web 应用程序,并且你的 GitHub webhook 配置正确,你应该看到构建在 Travis CI 上运行,每次推送 http://github.com/tensorflow/tensorflow.

有用的文档

但是,如果您没有存储库的管理员权限,您可以创建一个在您控制之下的存储库镜像,然后按照上面的说明操作(使用一些差异).根据我所做的小研究,如果没有原始/官方存储库的管理员访问权限,就不可能(或至少不容易)在 GitHub 上创建一个存储库的镜像.

However, if you do not have admin privileges on the repo, you could create a mirror of repository that is in your control and then follow the instructions above (with a few differences). From the little research I did, it's not possible (or at least not easy) to create a mirror of a repository all on GitHub without admin access of the original/official repository.

话虽如此,我找到了一个可行的解决方法.

With that said, I found a workaround that should work.

  1. tensorflow/tensorflow 导入 GitLab 并使用镜像存储库功能使其镜像 http://github.com/tensorflow/tensorflow 作为您的 GitLab 存储库的上游.

  1. Import tensorflow/tensorflow to GitLab and use the Mirror Repository feature so it mirrors http://github.com/tensorflow/tensorflow as your GitLab repo's upstream.

从那里开始,除了使用 GitLab 的 webhook API 而不是 GitHub 的发送推送事件来触发我们的 Web 应用程序在 Travis CI 上开始构建之外,照常按照上述说明进行操作.

From there, follow the instructions above as normal except use GitLab's webhook API instead of GitHub's to send push events to trigger our web app to start builds on Travis CI.

有用的文档

我希望这些信息对您有所帮助.如果您有任何其他问题,请告诉我,我很乐意尽我所能提供帮助.:)

I hope this information was helpful. Please let me know if you have any other questions and I'd be happy to help in any way I can. :)

这篇关于推送到不同的存储库时自动触发 Travis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆