Skip to content

Instantly share code, notes, and snippets.

@fulldecent
Created November 29, 2017 02:33
Show Gist options
  • Save fulldecent/d84cd1abdcc6930865d1b862c4aed917 to your computer and use it in GitHub Desktop.
Save fulldecent/d84cd1abdcc6930865d1b862c4aed917 to your computer and use it in GitHub Desktop.
Run Travis build locally

travis-local.md

Preconditions:

  1. POSIX or Windows system
  2. Install Docker
  3. A GitHub repo that already builds on Travis

Postcondition:

  • Identical output as if run from Travis

Project status:

  • Alpha quality, please post notes here and fork baby fork, I will try to test and accept changes here

Notes:

  1. Install Travis on Docker

    # choose 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 — 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 ssh key for Github
    ssh-keygen -t rsa -b 4096 -C “YOUR EMAIL REGISTERED IN GITHUB”
    
    # Click enter to use default location for key
    # You can choose empty passphrase by clicking enter twice
    # Now that we have the key, let’s share with Github
    less ~/.ssh/id_rsa.pub
    
    # Copy the contents of the id_rsa.pub
  2. Go to your Github SSH key settings

  3. Create a new ssh key with title: “docker key”: “PASTE THE KEY CONTENTS HERE”

  4. Go back to docker terminal

    # Create project dir, assuming your project is `AUTHOR/PROJECT` on GitHub
    cd ~/builds \
    mkdir AUTHOR \
    cd AUTHOR \
    git clone [email protected]:AUTHOR/PROJECT.git \
    cd PROJECT
    
    # change to the branch or commit you want to investigate
    # compile travis script into bash script
    travis compile > ci.sh
    
    # Go to bash script and fix the branch name
    vi ci.sh
    
    # in Vi type “/branch” to search and add the right branch name
    # — branch\=\’\NEW_BRANCH’\
    # You most likely will need to edit ci.sh as it ignores ‘matrix’ and ‘env’ keywords
    bash ci.sh
@ekivolowitz
Copy link

ekivolowitz commented Jun 20, 2018

@mikehardy I found a fix for this. See issue here. Be sure to use the issue_9709_fix branch.

@shijiezhou1
Copy link

9bd3d9c978b:~/builds/travis-build$ gem install travis
ERROR: Could not find a valid gem 'travis' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_conn
ect returned=1 errno=0 state=unknown state: tlsv1 alert protocol versio
n (https://api.rubygems.org/specs.4.8.gz)

I can't install please !

@thamaraiselvam
Copy link

@shijiezhou1 try to add HTTP

$ gem sources --remove https://rubygems.org/
$ gem sources -a http://rubygems.org/

@c5253458
Copy link

This works on one platform only: x86_64, as it depends on
quay.io/travisci/travis-jvm

@laszewsk
Copy link

laszewsk commented Mar 5, 2020

I get now

bundle install
bash: bundle: command not found

@sopansh-rapyuta
Copy link

sopansh-rapyuta commented Nov 1, 2021

Doesnt work,
First error is on gem install travis
RROR: Error installing travis: There are no versions of faraday-em_http (~> 1.0) compatible with your Ruby & RubyGems. Maybe try installing an older version of the gem you're looking for? faraday-em_http requires Ruby version >= 2.4.0. The current ruby version is 2.3.0.0.

If changed to ruby version 2.4.0, it is successful but later there is error on step : bundle install


travis@d55c93a80f58:~/builds/travis-build$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching https://github.com/joshk/jemalloc-rb
Fetching https://github.com/eric/metriks-librato_metrics
Fetching https://github.com/travis-ci/travis-github_apps
Fetching https://github.com/travis-ci/travis-rollout
Fetching https://github.com/travis-ci/travis-support
Fetching rake 12.3.3
Installing rake 12.3.3
Fetching concurrent-ruby 1.1.6
Installing concurrent-ruby 1.1.6
Fetching i18n 0.9.5
Installing i18n 0.9.5
Fetching minitest 5.14.0
Installing minitest 5.14.0
Using thread_safe 0.3.6
Fetching tzinfo 1.2.7
Installing tzinfo 1.2.7
Fetching activesupport 4.2.11.1
Installing activesupport 4.2.11.1
Fetching public_suffix 3.0.3
Installing public_suffix 3.0.3
Fetching addressable 2.5.2
Installing addressable 2.5.2
Fetching ast 2.4.0
Installing ast 2.4.0
Fetching atomic 1.1.101
Installing atomic 1.1.101 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/travis/.rvm/gems/ruby-2.4.0/gems/atomic-1.1.101/ext
/home/travis/.rvm/rubies/ruby-2.4.0/bin/ruby -I /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0 -r ./siteconf20211101-5604-bjwdnr.rb extconf.rb
checking for libkern/OSAtomic.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/home/travis/.rvm/rubies/ruby-2.4.0/bin/$(RUBY_BASE_NAME)
	--with-atomic_reference-dir
	--without-atomic_reference-dir
	--with-atomic_reference-include
	--without-atomic_reference-include=${atomic_reference-dir}/include
	--with-atomic_reference-lib
	--without-atomic_reference-lib=${atomic_reference-dir}/lib
/home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:457:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:588:in `try_cpp'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:1095:in `block in have_header'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:945:in `block in checking_for'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:351:in `block (2 levels) in postpone'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:321:in `open'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:351:in `block in postpone'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:321:in `open'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:347:in `postpone'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:944:in `checking_for'
	from /home/travis/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/mkmf.rb:1094:in `have_header'
	from extconf.rb:17:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/travis/.rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/atomic-1.1.101/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/travis/.rvm/gems/ruby-2.4.0/gems/atomic-1.1.101 for inspection.
Results logged to /home/travis/.rvm/gems/ruby-2.4.0/extensions/x86_64-linux/2.4.0/atomic-1.1.101/gem_make.out

An error occurred while installing atomic (1.1.101), and Bundler cannot continue.
Make sure that `gem install atomic -v '1.1.101' --source 'https://rubygems.org/'` succeeds before bundling.

even if tried to use http instead of https as gem source it doesn't work.

I am using docker image for python: travisci/ci-python:packer-1490914243

Anyone had same issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment