LoginSignup
11
8

More than 5 years have passed since last update.

circle-ciでversion2.1を使ってみる

Last updated at Posted at 2018-11-10

tl;dr

version2.1だと結構便利な機能がいろいろ追加されているようなので使ってみる。

  • executors
  • commands
  • workflows (version 2.0)

とにかく書いてみる

.circleci/config.yml
version: 2.1

executors:
  default:
    working_directory: ~/repo
    docker:
      - image: circleci/php:7

commands:
  composer_install_with_cache:
    steps:
      - restore_cache:
          keys:
            - v1-composer-deps-{{ checksum "composer.json" }}
            - v1-composer-deps-
      - run: composer install -n --prefer-dist
      - save_cache:
          key: v1-composer-deps-{{ checksum "composer.json" }}
          paths:
            - ./vendor

jobs:
  checkout_code:
    executor: default
    steps:
      - checkout
      - composer_install_with_cache
      - save_cache: # ソースコードをキャッシュ
          key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
          paths:
            - ~/repo

  test:
    executor: default
    steps:
      - restore_cache: # ソースコードの復元
          key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}

      - run: phpunit

workflows:
  version: 2
  build:
    jobs:
      - checkout_code
      - test:
          requires: # checkout_codeの後に実行する
            - checkout_code

設定ファイルチェック

記述が間違っていないかチェックする。

ターミナル
$ circleci config validate
Config file at .circleci/config.yml is valid.

実行結果

Workflowを使ったことで下記のようにジョブが2つ実行されました。
job.png

version2.1になると各処理をスッキリ書けていい感じですね。

ローカル実行について

ローカル実行しようとすると対応していないとエラーになるのが残念。

ターミナル
$ circleci local execute
Error: 
You attempted to run a local build with version '2.1' of configuration.
Local builds do not support that version at this time.
You can use 'circleci config process' to pre-process your config into a version that local builds can run (see 'circleci help config process' for more information)

ただし、下記のコマンドで2.0に変換すれば実行可能なようです。

ターミナル
# 設定ファイルの変換 (2.1 -> 2.0)
$ circleci config process .circleci/config.yml > process.yml

# チェックアウトのジョブを実行
$ circleci local execute -c process.yml --job checkout-code
  ・
  ・
  ・
====>> echo "compoer install."
  #!/bin/bash -eo pipefail
compoer install -n --prefer-dist
====>> Saving Cache
Error: 
Skipping cache - error checking storage: not supported

Step failed
Success!

# テストのジョブを実行
$ circleci local execute -c process.yml --job test

キャッシュでエラーが出たり、ジョブを個別に実行するなど、ひと手間かかったりとちょっと面倒ではありますね。

参考サイト・資料

11
8
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
11
8