Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reproduce a travis-ci build environment for debugging

Tags:

travis-ci

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.

like image 504
David Roundy Avatar asked Apr 20 '15 16:04

David Roundy


People also ask

How do you debug a Travis build?

The “Debug build” or “Debug job” button is available on the upper right corner of the build and job pages for private repositories. For open source repositories, this button is not available and you will need to use an API call instead.

Which file is used to configure the Travis CI?

3) To set up a build environment and prepare the build, Travis CI's system fetches and processes the . travis. yml config file from the repository and the branch explicitly specified in the build request, triggered by GitHub.

How do you trigger Travis CI?

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.


2 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 
like image 55
eregon Avatar answered Sep 23 '22 17:09

eregon


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:

  1. Fork the repo (or use separate branch).
  2. After initial commit, keep adding --amend to replace your previous commit:

    git commit --amend -m 'Same message.' -a 
  3. Push the amended commit by force (e.g. into already opened PR):

    git push fork -f 
  4. Now Travis CI would re-check the same commit over and over again.


See also: How to run travis-ci locally.

like image 42
kenorb Avatar answered Sep 24 '22 17:09

kenorb