Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57983

Automatically triggering Travis on push to a different repository?

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

Upvotes: 2

Views: 1451

Answers (1)

Luna G.
Luna G.

Reputation: 156

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

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.

This would entail:

  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.

  2. 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).

Here's my example of that.

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. And voila! Once this web app is deployed, and your GitHub webhook is configured properly, you should see builds to run on Travis CI with every new push on http://github.com/tensorflow/tensorflow.

Helpful documentation

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. 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.

  2. 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.

Helpful documentation

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. :)

Upvotes: 4

Related Questions