首页 文章

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

提问于
浏览
53

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

4 回答

  • 11

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

    以下步骤只是指导,以使您进入正确的轨道(如果有任何遗漏,请告诉我) .

    本地

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

    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 compile 之后,您可以使用use vagrant使用提供的 Vagrantfile 以及以下步骤将此脚本运行到虚拟化环境中:

    vagrant up
    vagrant ssh
    cd /vagrant
    bundle exec rspec spec
    

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


    这里有一些 git 提示,它可以避免在为Travis CI测试进行试验和错误提交时生成不必要的提交:

    • 分叉回购(或使用单独的分支) .

    • 初始提交后,继续添加 --amend 以替换以前的提交:

    git commit --amend -m 'Same message.' -a
    
    • 强制推送修改后的提交(例如进入已经打开的PR):
    git push fork -f
    
    • 现在Travis CI会一遍又一遍地重新检查同一个提交 .
  • 12

    对于基于容器的构建,现在有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
    
  • 39

    我现在面临同样的问题 . 之前我曾使用CircleCI,您可以通过ssh登录VM,但这不适用于Travis-CI VM .

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

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

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

  • 3

    Eregon的回答在 travis compile 失败了,错误看起来像:

    /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
    

相关问题