CI 工具

先看可以支援的語言

\ Drone Travis
相同 C / C++
Go
Haskell (New)
Groovy (New)
Java
Node.js
PHP (Beta)
Python (Beta)
Ruby (Beta)
Scala (New)
C / C++
Go
Haskell
Groovy
Java
JavaScript (with Node.js)
PHP
Python
Ruby
Scala
不同 Dart Android
Clojure
Erlang
Objective-C
Perl

使用三步驟

  1. sign in Travis
  2. Activate GitHub Webhook
  3. Add .travis.yml file to your repository

驗證.travis.yml

  1. 可以透過這個Travis WebLint驗證.travis.yml的正確性
  2. 或者可以安裝travis-lint(requires Ruby 1.8.7+ and RubyGems install)
# 安裝指令
gem install travis-lint

# Usage:
# inside a repository with .travis.yml
travis-lint

# from any directory
travis-lint [path to your .travis.yml]

travis-lint功能

  • 提供驗證 .travis.yml
  • 檢查 language(請見上表)
  • 檢查特定的執行環境-VM-images)(見下方jdk)
# 例如Travis有提供`java`,沒有提供`Dart`
# 這樣就會報錯
# language: Dart
language: java
# 執行環境
jdk:
  - oraclejdk8
  - oraclejdk7
  - openjdk7
  - openjdk6

Configuring your build

Build Lifecycle

  1. Clone project repository from GitHub
  2. cd to clone directory
  3. Checkout commit for this build
  4. Run before_install commands
    Use this to prepare the system to install prerequisites or dependencies
    e.g. sudo apt-get update
  5. Run install commands
    Use this to install any prerequisites or dependencies necessary to run your build
  6. Run before_script commands
    Use this to prepare your build for testing
    e.g. copy database configurations, environment variables, etc.
  7. Run test script commands
    Default is specific to project language
    All commands must exit with code 0 on success. Anything else is considered failure.
  8. Run after_success or after_failure commands
  9. Run after_script commands

Specify branches to build

可以指定git branch的白名單以及黑名單,也可以使用regualr expression

# blacklist
branches:
  except:
    - legacy
    - experimental

# whitelist
branches:
  only:
    - master
    - stable
    - /^deploy-.*$/

The Build Matrix

下面的範例來說,要build 56次

rvm:
  - 1.8.7
  - 1.9.2
  - 1.9.3
  - rbx-2
  - jruby
  - ruby-head
  - ree
gemfile:
  - gemfiles/Gemfile.rails-2.3.x
  - gemfiles/Gemfile.rails-3.0.x
  - gemfiles/Gemfile.rails-3.1.x
  - gemfiles/Gemfile.rails-edge
env:
  - ISOLATED=true
  - ISOLATED=false

You can also define exclusions to the build matrix:

matrix:
  exclude:
    - rvm: 1.8.7
      gemfile: gemfiles/Gemfile.rails-2.3.x
      env: ISOLATED=true
    - rvm: jruby
      gemfile: gemfiles/Gemfile.rails-2.3.x
      env: ISOLATED=true

Pre Install

Travis 本身有預先安裝一些東西,例如現在我想要使用 gradle 2.1,但是 Travis 現在提供的是 gradle 2.0,下面是更換 Travis 預設設定的方式。

before_install:
  - sudo rm -r /usr/local/gradle
  - curl -LO https://services.gradle.org/distributions/gradle-2.1-bin.zip
  - unzip -q gradle-2.1-bin.zip
  - sudo mv gradle-2.1 /usr/local/gradle

How to skip a build

並不是所有的 Commit 都需要進行 Travis Build,可以透過在 commit 的說明中(任何地方都可),添加[ci skip] or [skip ci]


Speeding up the build


Build Environment

這邊說明了 Travis 預設狀態下,事先安裝了什麼東西


Custom Deployment


Source:

Command line:

Lint check your .travis.yml