Enable travis build on all git branches, how to check out the code to a subdirectory

I would like to know how to enable travis build on all git branches of my repo. The travis yml does a git clone of the repo and then does a catkin build.
So for a commit in any branch, it always clones the repo, goes to the master branch and builds the master branch. How do I enable travis for all branches.

You can check out the branch you want in before_install:

  - git checkout master

But why do you want to do that? It defeats the whole purpose of CI.

I do not want to checkout to any branch. My problem is that I want travis to build the branch (let it be any branch) where a git push is done. Currently it always builds just the master branch.

It surprises me that this is not happening now. Can you link to the build URL you think the problem is happening?

https://travis-ci.org/tomin11/library-unit-test/branches has 2 branches called master and test.
I have removed a semi colon from a cpp file in test on purpose. so test build has to fail. but it passes. could you please check my travis file too.
Thanks a lot in advance.

In the test branch build https://travis-ci.org/tomin11/library-unit-test/builds/573957229#L174, you see that we check out the commit in question correctly. If you look at the content of that file with cat lib_test/src/prog.cpp, you will see the semicolon gone.


I don’t know how your repo is set up, so I can’t tell you why this change doesn’t fail the build. I will guess that it is not a part of the build.

Thanks. A catkin build on my system fails. So I am not sure why travis should not fail. How exactly does travis build branches. The travis yml clones the repo. And builds the default branch : master branch. All the branches of the repo have the same travis.yml. I am unclear about how travis builds individual branches. @BanzaiMan


I see that

You are moving to $CATKIN_WS/src and cloning https://github.com/tomin11/library-unit-test.git at its default branch, which I guess is master.

Further down , you move to $CATKIN_WS and run the commands:

I don’t know what catkin command is supposed to do, but if it is using the src subdirectory to run your builds, it will see the source as found in the default branch, not the branch you are running builds on.

All of this is written in your .travis.yml.

yes so does that mean i need separate travis.yml files for different branches of the repo where i add a step where i checkout to that branch before the catkin build?

I don’t know what you need, so I can’t advise any more than this.

suppose my repo has branches a,b,c.
what i want is that when i push a commit to a, i want a to be built by travis. when i push something to b i want b to be built by travis.

$ export CATKIN_WS=~/ws_catkin
$ mkdir -p $CATKIN_WS/src
$ cd $CATKIN_WS/src
$ git clone https://github.com/tomin11/library-unit-test.git

The above is completely unnecessary since Travis build logic already checks out your repository, at the commit to be tested.

So just do

export CATKIN_WS=$(pwd)

in your script if you need that envvar to be pointing to the directory with your code.

Hey thanks for your reply @native-api
removing the unnecessary part i get an error that says there is no source space

If the tool you are using expects your code checkout to be inside some specific directory hierarchy, you can create that hierarchy, then make the necessary entry a symlink to the checkout directory or just move the checkout directory there (since Git 1.7.10, checkout directories can be freely moved around).
I leave the details specific to your case as an exercise for you.