如何重现travis-ci构建环境以进行调试

时间:2015-04-20 16:39:25

标签: travis-ci

我看到travis-ci上的构建失败,我无法在本地机器上重现。是否有设置VM的说明与travis-ci linux构建环境相同?我很高兴travis-ci已经发现了一个新的错误,但通过发送添加调试代码的提交来调试它不那么兴奋。

4 个答案:

答案 0 :(得分:39)

对于基于容器的构建,现在有instructions on how to setup a docker image locally

不幸的是,相当多的步骤仍然是手动的。以下是启动和运行所需的命令:

# 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

答案 1 :(得分:12)

我现在面临同样的问题。我曾经使用过CircleCI,你可以通过ssh登录到VM,但这不适用于Travis-CI VM。

我可以通过Travis-Cookbooks设置Travis-ci VM克隆来调试它(到某一点)。在克隆此存储库之前,您需要先在计算机上安装VirtualBoxVagrant

克隆Travis-Cookbooks后,打开文件夹,启动命令提示符|终端并键入vagrant up。一旦Vagrant完成在您的计算机上设置VM(可能需要很长时间),您可以通过运行vagrant ssh来通过ssh连接到它。

从那里,您需要克隆自己的存储库(或者只是将代码复制到VM)并应用.travis.yml文件中的步骤。

答案 2 :(得分:11)

您可以使用Travis Build这是一个库(这意味着您可以将其放在~/.travis/中)以生成基于shell的构建脚本(travis compile),该脚本可以是然后使用SSH上传到VM并执行。

以下步骤只是为了让您走上正确的轨道(如果遗漏了任何内容,请告诉我们)。

泊坞

运行容器的示例命令(可以在Docker Hub找到):

docker run -it travisci/ubuntu-ruby:18.04 /bin/bash

运行您的容器,克隆您的存储库,然后手动测试它。

请参阅:Running a Container Based Docker Image Locally

SSH访问

查看此answer。基本上你需要设置退回主机,然后配置你的构建以运行SSH隧道。

以下是示例.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

本地设置

以下是在本地环境中测试它的步骤:

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

流浪/ VM

在您travis compile生成bash脚本的.travis.yml之后,您可以使用use vagrant使用提供的Vagrantfile将此脚本运行到虚拟化环境中,并执行以下步骤:

vagrant up
vagrant ssh
cd /vagrant
bundle exec rspec spec

您可能需要安装更多工具才能对其进行测试。

以下是一些git提示,可以避免您在进行试用时生成不必要的提交。错误提交Travis CI测试:

  1. 分叉回购(或使用单独的分支)。
  2. 初次提交后,继续添加--amend以替换之前的提交:

    git commit --amend -m 'Same message.' -a
    
  3. 强制推送修改后的提交(例如,进入已打开的PR):

    git push fork -f
    
  4. 现在Travis CI会一遍又一遍地重新检查相同的提交。

  5. 另请参阅:How to run travis-ci locally

答案 3 :(得分:3)

travis compile,Eregon的回答对我来说失败了,错误看起来像是:

/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)

我使用了以下调整:(标有#CHANGED 的调整。我使用节点环境)

# 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
相关问题