How to trigger a build in the test project upon a commit to dev project with Travis CI API

Hi,

I am working on JavaScript and Node.js project. In my project, the dev code of the product and an automated test script framework is placed in different GitHub repositories.
Now, the issue is that I don’t know how to run my test script if any commit is pushed to the Dev repository. As we need to add the .travis.yml file in the repository from where the build will trigger.

I contact the support team they said “you may consider using the API to trigger a build from one repo to another.”

As I’m very new to Travis-ci so, I have no idea how to deal with API.

Can anyone help me to make things happen and can provide more clearance about the things from where I need to start.

Thanks in advance !!

It’ll probably be easier to make the test repo a submodule of the dev repo, or check it out manually in the build logic in the dev repo.

  • (The practical difference is: for a submodule, the SHA of the test repo commit to check out is held statically in Git metadata in the dev repo, while if you check it out manually, you can check out whichever commit you want. On the other hand, Travis checks out submodules automatically by default and if you don’t hold the test commit info in Git metadata, you’ll still need to hold the info necessary to make a decision somewhere).
  • Then the dev build logic will call the necessary script to run the tests from the resulting checkout.

This way, you’ll see the test result right in the build for the dev commit. If you trigger a build in the test repo instead, that build will have the test result and you won’t readily see in the dev project if a particular commit is good or not.


Now, for your specific question:

For how to trigger a Travis build via API, see Triggering builds with API V3 - Travis CI .
You’ll need to

  • give the dev build a Travis token with access to the test project (as a secret variable) to authenticate the request;
  • pass the triggered build some info for it to be able to check out the necessary dev commit – probably as envvars in the custom config in the request:
    body='{
     "request": {
     "branch":"<...>",
     "config": {
       "env": {
         "global": [
           "DEV_SHA=<...>",
           "DEV_BRANCH=<...>"
         ]
       },
      }
    }}'
    
  • In the test repo build, use this data to check out the necessary commit from the dev repo

This way, the dev build will always succeed (as long as it could trigger the test build) and you won’t see the test result in the dev repo. To pass the result to the dev build, you’ll need to somehow stall in the dev build and wait for the test build result (via Travis API). You can easily run into the job time limit, and it will be wasting your credits (if you’re on a credits-based plan) or a concurrency unit (if on a concurrency-based plan) while waiting.

  • This is why I see this way as an unnecessary complication and do not recommend it.
1 Like

@native-api Thanks for your response! The information you provided will help me to move forward with the next steps.

I fully agree with the approach you explained. But at this time I just want to play with API that how it will work with different GitHub repositories.

Now, I have more questions about the answer you have provided. that is

  • where do we need to add this request info and how can we fetch this in the test repo.
  • Do we need to add this info in .travis.yml file or any other file?
  • What will the content of .travis.yml file in the test repo and in the dev repo?

If possible, can you provide more details about the API that how it will trigger a build on a new commit?

Thanks!!

Didn’t quite understand what “request info” you’re referring to.
The links and information I gave show how to make the request and how to pass additional information to the triggered build with it.

In the build logic. I.e. either in .travis.yml directly, or in some script that it will call.

If you wish me to make a full solution for your specific case, I can do that for a couple of bucks. PM me if you’re interested. I’ll require additional info since in the light of your last message, even your goals are unclear.

Thanks for your support.

Firstly, let me try all the provided solutions by you. If this has not been solved then I will PM you.
Thank You!

Imprint