LoginSignup
122
117

More than 5 years have passed since last update.

CircleCIの便利な機能

Last updated at Posted at 2014-10-09

CircleCIの設定をする際に便利だった機能について書く。

便利な機能

ssh接続

ビルド結果画面にある「&enable SSH」をクリックすると別インスタンスが起動し、ssh接続可能になる。

「ローカルでは動くか、CI上では動かない」などのトラブル調査の際に便利。

standfirm_sfinvoice__245_-_CircleCI.png

circle.ymlで設定可能な項目(抜粋)

Configuring CircleCIからの抜粋。

/etc/hostsへの登録

名前解決できないテスト用サーバ等を設定するとよい。

machine:
  hosts:
    dev.circleci.com: 127.0.0.1
    foobar.com: 1.2.3.4

環境変数の登録

環境変数はWebUIでも設定可能ですが、circle.ymlの内容が優先されます。

machine:
  environment:
    foo: bar
    baz: 123

タイムゾーン

デフォルトではUTCになっているので、日本にしておいたほうが無難。

machine:
  timezone:
    Asia/Tokyo

任意コマンドの実行

prepostに任意のコマンドが書ける。

machine:
  pre:
    - echo foo
    - echo bar
  post:
    - echo baz

ビルド

任意コマンドの実行

machineと同様にprepostが利用できる。

dependencies:
  pre:
    - sudo cp .env.sample .env

特定ディレトリのキャッシュ

複数のビルド間で共有するディレクトリを指定する。
あまりサイズが大きくなるとつらい。(例: /usr を指定したら10分くらい待たされた)

dependencies:
  cache_directories:
    # 絶対パス
    - /path/to/cache
    # 相対パス
    - cache
    # /homeからの相対パス
    - ~/cache

pre と組合せて独自でいれるソフトウェアのキャッシュができる。

dependencies:
  cache_directories:
    - redis-2.4.18
  pre:
    - if [[ ! -e redis-2.4.18/src/redis-server ]]; then wget http://redis.googlecode.com/files/redis-2.4.18.tar.gz && tar xzf redis-2.4.18.tar.gz && cd redis-2.4.18 && make; fi

テスト

任意コマンドの実行

machineと同様にprepostが利用できる。

test:
  pre:
    - bundle exec rubocop

テストコマンドの変更

override でテストのコマンドを変更できる。CircleCI自体をいじるときは、ここを適当なコマンドに差し替えると楽。

test:
  override:
    - echo "Ya! All the tests are passed!!"
122
117
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
122
117