Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 1046 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Limit Built Branches on Travis

3:38 JavaScript lesson by

By default, Travis will build all branches, tags, and Pull Requests. Because we're building our master branch before we release, we don't need Travis building our releases. Also, we don't care to have Travis build all the branches. So we're going to limit Travis to only build our master branch and Pull Requests by configuring travis via our .travis.yml file.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

By default, Travis will build all branches, tags, and Pull Requests. Because we're building our master branch before we release, we don't need Travis building our releases. Also, we don't care to have Travis build all the branches. So we're going to limit Travis to only build our master branch and Pull Requests by configuring travis via our .travis.yml file.

Avatar
Philip

Super awesome series, can't wait to get stuck into an open-source project!

In reply to egghead.io
Avatar
Richard Hoffmann

Hi Kent, thanks for the awesome series.

Currently with babel 6.0 i have a problem getting tests to pass in travis, it always fails with

Error: Cannot find module babel/register

I tried to add babel-cli as a before install script:

before_install:
  - npm i -g npm@^2.0.0
  - npm i -g babel-cli

but no luck so far. Do you have any idea how to fix this?

Thanks in advance,
Richard

Avatar
Kent C.

As I'm sure you're aware, babel 6.0 was just released last week and has many major breaking changes. I'm not certain what that means for this project. I'm afraid that I haven't had a moment to try things out yet. I'll let you know as soon as I figure out a solution for it (or you can if you figure it out first :-))

In reply to Richard Hoffmann
Avatar
fpaxton

I made a couple of comments on the previous two lessons that solved this for me.

In reply to Richard Hoffmann

If you look at the badges on our ReadMe, we'll see that our build is failing. Let's go ahead and take a look at our build. What's actually failing, is there was a problem with one of the lessons that I deployed, and that build failed.

But it's showing up that our build is failing and we don't really want that, the actual master build, the releases, those are all passing, and so what we're going to do is we're going to tell Travis that we only want to build specific branches and we don't want to build any of the lesson branches or anything else, it will be just specific branches that we explicitly mention. To do this, we are going to go ahead and jump into our travis.yml file, and we'll add a branches here with an only, and we'll specify master.

So we're only going to build master. Now Travis will automatically continue to build the pull request which is something that we definitely want, so that when somebody makes a pull request we can see that their pull request will merge, and that the build will continue to pass. But we only want to build our master branch, and then we can list other branches and it actually takes regex here.

This is a white list, you can do a black list with exclude, but we're just going to do a white list with only, and now all that we need to do is commit this change. So let's look at our Git status, we have that modified file. Let's do Git add and Git status, so now we can run npm run commit and we'll go through our commit is in, this is a chore related to Travis, only build master and PRs because we don't want to waste resources, save the trees.

We'll go ahead and add a tree emoji, probably a Christmas tree is good, and we don't have any issues related to this change, so we'll just skip that. Now that all of our commit hooks have passed and everything is worked out, our commit succeeded, now we'll go ahead and push. If we look at our Travis build at the current here in a moment, it will update to what we just pushed. There it is. Save the trees, and it's building.

Now we can verify this by creating a branch, let's say Git checkout branch Lesson/23 limit Travis Builds and we'll go ahead and push this branch, specifying origin, lesson 23 and that will get pushed as a new branch to our Git repository. If we look at the build history here, we see that no longer will our lessons be built and that is how you limit Travis from building any extra branches and so now if we go to our repo, and we'll refresh here.

The build is now passing, and that is exactly what we want. Just to review things really quick, if we go to our travis.yml we simply add this branches property, we white list our master branch, and anything else that doesn't match this or a regex in this place to be built. That is how you limit Travis from building extra branches.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?