Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger travis ci builds if another git repository updates [duplicate]

Tags:

travis-ci

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

like image 700
Yaroslav Bulatov Avatar asked Dec 04 '17 20:12

Yaroslav Bulatov


People also ask

How do you trigger a Travis CI build?

Trigger Travis CI builds using the API V3 by sending a POST request to /repo/{slug|id}/requests : Get an API token from your Travis CI settings page. You'll need the token to authenticate most of these API requests.

Which of the following build automation tool can be used with Travis CI?

Travis CI supports parallel testing. It can also be integrated with tools like Slack, HipChat, Email, etc. and get notifications if the build is unsuccessful. Developers can speed up their test suites by executing multiple builds in parallel, across different virtual machines.

Which of the following analysis tool is used for code coverage in Travis CI?

Coveralls is a hosted analysis tool, providing statistics about your code coverage. Configuring your Travis CI build to send results to Coveralls always follows the same pattern: Add your repository to Coveralls.


1 Answers

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

  • https://docs.travis-ci.com/user/triggering-builds/
  • https://developer.github.com/webhooks/
  • https://developer.github.com/webhooks/configuring/

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

  • https://about.gitlab.com/2016/12/01/how-to-keep-your-fork-up-to-date-with-its-origin/
  • https://docs.gitlab.com/ce/user/project/integrations/webhooks.html

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

like image 113
Luna G. Avatar answered Oct 03 '22 01:10

Luna G.