I am seeing a build failure on travis-ci, which I cannot reproduce on my local machine. Are there instructions somewhere for setting up a VM that is identical to the travis-ci linux build environment? I'm glad to have travis-ci already reveal a new bug, but less excited to debug it by sending in commits that add debug code.
-
3Possible duplicate of [How to run travis-ci locally](http://stackoverflow.com/questions/21053657/how-to-run-travis-ci-locally) – Seanny123 Dec 01 '16 at 06:32
-
1@Seanny123: I don't think that one is as complete as this one is. In fact, folks are linking from that one to this one. – Jim Meyer Feb 17 '17 at 17:32
-
any reason you don't just login to Travis while it's in debug mode? – iconoclast Mar 02 '19 at 19:31
4 Answers
For container-based builds, there are now instructions on how to setup a docker image locally.
Unfortunately, quite a few steps are still manual. Here are the commands you need to get it up and running:
# change the image according to the language chosen in .travis.yml
$ docker run -it -u travis quay.io/travisci/travis-jvm /bin/bash
# now that you are in the docker image, switch to the travis user
sudo su - travis
# Install a recent ruby (default is 1.9.3)
rvm install 2.3.0
rvm use 2.3.0
# Install travis-build to generate a .sh out of .travis.yml
cd builds
git clone https://github.com/travis-ci/travis-build.git
cd travis-build
gem install travis
travis # to create ~/.travis
ln -s `pwd` ~/.travis/travis-build
bundle install
# Create project dir, assuming your project is `me/project` on GitHub
cd ~/builds
mkdir me
cd me
git clone https://github.com/me/project.git
cd project
# change to the branch or commit you want to investigate
travis compile > ci.sh
# You most likely will need to edit ci.sh as it ignores matrix and env
bash ci.sh

- 24,651
- 6
- 70
- 114

- 1,486
- 14
- 15
-
1This didn't work for me, because the wrong branch was being detected. – Seanny123 Dec 01 '16 at 06:31
-
@Seanny123 The branch of your repository? Then I would expect a simple `git checkout mybranch` before running `travis compile` would work just fine. – eregon Dec 04 '16 at 10:49
-
1Can you duplicate this answer to [this question](http://stackoverflow.com/questions/21053657/how-to-run-travis-ci-locally) where I have a bounty. Your answer is the closest thing to what I wanted. – Seanny123 Dec 08 '16 at 08:39
-
@Seanny123 I replied as a comment to the accepted answer. I am not sure if it's OK to duplicate answers and I did not see the bounty. – eregon Dec 09 '16 at 10:25
-
-
2Thanks, I had to modify the ci.sh to manually enter my branch name, after that It worked like a charm, thanks. – moxi Jan 29 '17 at 01:52
-
@Seanny123 I added my answer to the other question as well: http://stackoverflow.com/a/41935867/388803 – eregon Jan 30 '17 at 12:24
-
Per @moxi, I had to add my branch name to the generated `ci.sh` (otherwise it tries to clone with `--branch=''` and fails). Likewise, I had to do some messing around to get `travis compile` to run successfully: I added `gem "travis"` to `~/builds/travis-build/Gemfile`, ran `bundle install`, then `bundle exec bash -c "cd ~/builds/my/repo; travis compile" > ~/builds/my/repo/ci.sh`. Otherwise I got errors about `travis/support` not being found. – Asherah Aug 07 '17 at 01:19
-
After running bundle install, it says: Post-install message from atomic: This gem has been deprecated and merged into Concurrent Ruby (http://concurrent-ruby.com) Should some part of the script be updated? – ario Aug 18 '17 at 15:15
-
@ario Please report issues on https://github.com/travis-ci/travis-build or https://github.com/travis-ci/travis-ci/issues then. But a deprecated warning is not much to worry about. – eregon Aug 19 '17 at 16:13
-
just for clarification, does that means we can use these docker images without buying Travis packages or enterprise edition? – Anoop Philip Aug 30 '17 at 00:49
-
-
2If you get an error saying: `kernel_require.rb:120:in require: cannot load such file -- travis/support (LoadError)`... then you need to run [some extra commands](https://github.com/travis-ci/travis-ci/issues/8098#issuecomment-321507488) – Ian Dunn Feb 27 '18 at 21:06
You can use Travis Build which is a library (which means you've to place it in ~/.travis/
) to generate a shell based build script (travis compile
) which can be then uploaded to the VMs using SSH and executed.
Below steps are just guidance in order to get you into the right track (if anything is missing, let me know).
Docker
Example command to run container (which can be found at Docker Hub):
docker run -it travisci/ubuntu-ruby:18.04 /bin/bash
Run your container, clone your repository then test it manually.
See: Running a Container Based Docker Image Locally
SSH access
Check out this answer. Basically you need to setup bounce host, then configure your build to run SSH tunnel.
Here is the example .travis.yml
:
sudo: required
dist: trusty
language: python
python: "2.7"
script:
- echo travis:$sshpassword | sudo chpasswd
- sudo sed -i 's/ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
- sudo service ssh restart
- sudo apt-get install sshpass
- sshpass -p $sshpassword ssh -R 9999:localhost:22 -o StrictHostKeyChecking=no travisci@$bouncehostip
Local setup
Here are the steps to test it on your local environment:
cd ~
git clone https://github.com/travis-ci/travis-build.git
ln -s ~/travis-build/ ~/.travis/travis-build
sudo gem install bundler
bundle install --gemfile ~/.travis/travis-build/Gemfile
cd repo-dir/
travis login -g <github_token>
vim .travis.yaml
travis lint # to validate script
travis compile # to transform into shell script
Vagrant/VM
After you did travis compile
which would produce the bash script as result of your .travis.yml
, you can use use vagrant to run this script into virtualized environment using provided Vagrantfile
and the following steps:
vagrant up
vagrant ssh
cd /vagrant
bundle exec rspec spec
You probably need to install more tools in order to test it.
Here is some git
hint which avoids you to generates unnecessary commits when doing trial & errors commits for Travis CI testing:
- Fork the repo (or use separate branch).
After initial commit, keep adding
--amend
to replace your previous commit:git commit --amend -m 'Same message.' -a
Push the amended commit by force (e.g. into already opened PR):
git push fork -f
Now Travis CI would re-check the same commit over and over again.
See also: How to run travis-ci locally.

- 155,785
- 88
- 678
- 743
-
-
@tommarshall You should check which one is running on CI. Usually you've this info on build log in _Build system information_ section at the beginning. My tests are using trusty for example. – kenorb Jul 27 '16 at 15:02
-
2The build information indicates the dist, but I don't believe the script generated from `travis compile` sufficiently bootstraps a vanilla `ubuntu/trusty64` vagrant box ahead of the tests. I think you'd have to provision the vanilla box with the travis cookbooks first. I managed to find a pre-packaged box https://atlas.hashicorp.com/travis-ci/boxes/ci-minimal-trusty64 appears to be working in my case, despite being over a year old. – tommarshall Jul 27 '16 at 15:31
I'm facing the same issue right now. I used to use CircleCI before, where you could just login to VM via ssh, but this doesn't work with Travis-CI VMs.
I was able to debug it (to a certain point) by setting up Travis-ci VM clone via Travis-Cookbooks. You would need to install VirtualBox and Vagrant on your computer first before cloning this repository.
Once you have Travis-Cookbooks cloned, open the folder, launch command prompt|terminal and type vagrant up
. Once Vagrant finishes setting up VM (may take a long time) on your machine, you can connect to it via ssh by running vagrant ssh
.
From there, you would need to clone your own repository (or just copy the code to VM) and apply the steps from your .travis.yml
file.
-
1I've just gotten vagrant with travis-cookbooks up and running, and am running into some confusion. It looks like when I `vagrant ssh precise64`, I get an almost completely empty VM, not even with git installed. Is that how it is supposed to work? – David Roundy May 01 '15 at 21:39
-
@DavidRoundy, Yeah, I noticed that too. I just copied my project files over to VM and run the script from there. Unfortunately, with no proper Docker support we had to put Travis-CI aside for now. – Timka May 05 '15 at 13:59
Eregon's answer failed for me at travis compile
, there error looks like:
/home/travis/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- travis/support (LoadError)
I got it working with the following adjustments: (Adjustments marked with # CHANGED. I'm using the node environment)
# change the image according to the language chosen in .travis.yml
# Find images at https://quay.io/organization/travisci
docker run -it quay.io/travisci/travis-node-js /bin/bash
# now that you are in the docker image, switch to the travis user
su travis
# Install a recent ruby (default is 1.9.3) to make bundle install work
rvm install 2.3.0
rvm use 2.3.0
# Install travis-build to generate a .sh out of .travis.yml
sudo mkdir builds # CHANGED
cd builds
sudo git clone https://github.com/travis-ci/travis-build.git
cd travis-build
gem install travis
travis # to create ~/.travis
ln -s `pwd` ~/.travis/travis-build
bundle install
bundler add travis # CHANGED
sudo mkdir bin # CHANGED
sudo chmod a+w bin/ # CHANGED
bundler binstubs travis # CHANGED
# Create project dir, assuming your project is `me/project` on GitHub
cd ~/builds
mkdir me
cd me
git clone https://github.com/me/project.git
cd project
# change to the branch or commit you want to investigate
~/.travis/travis-build/bin/travis compile > ci.sh # CHANGED
# You most likely will need to edit ci.sh as it ignores matrix and env
# In particular I needed to edit --branch=’’ to the branch name
bash ci.sh

- 1,727
- 4
- 19
- 28
-
Any idea why Eregon's answer didn't work and why these changes fix that? I just ran into the same thing and I can confirm your changes worked for me. – rofer Oct 22 '17 at 19:29