LoginSignup
4
1

More than 5 years have passed since last update.

CircleCI で複数の実行環境で同じジョブを実行する

Posted at

目標

例えば、 TravisCI でできるような、こういう感じのテストを設定したいのです。

.travis.yml
language: python
python:
  - "2.7"
  - "3.6"

script:
  - make check

Python 2.7, 3.6 に対して同じテストを実行し、全部通ったら OK としたいです。

ベタなやり方

コマンドを2箇所に書きます。

.circleci/config.yml
---
version: 2
workflows:
  version: 2
  test:
    jobs:
      - test-2.7
      - test-3.6

jobs:
  test-2.7:
    docker:
      - image: circleci/python:2.7
    steps:
      - checkout
      - run:
          name: Run tests
          command: make check
  test-3.6:
    docker:
      - image: circleci/python:3.6
    steps:
      - checkout
      - run:
          name: Run tests
          command: make check

この書き方は明らかに冗長です。 steps の記述が重複していてあとでつらくなりそうです。

コマンド記述部をまとめる

YAML の Anchor と Alias をこの目的に使うことができます。

  • Anchor のついたデータを、 Alias から参照することができます
  • 同レベルにマッピングを追加することで、参照したマッピングにその場で(参照元を書き換えたりはせずに)値を追加・上書きできます
.circleci/config.yml
---
version: 2
workflows:
  version: 2
  test:
    jobs:
      - test-2.7
      - test-3.6

_test-body: &test-body
  steps:
    - checkout
    - run:
        name: Run tests
        command: make check

jobs:
  test-2.7:
    <<: *test-body
    docker:
      - image: circleci/python:2.7
  test-3.6:
    <<: *test-body
    docker:
      - image: circleci/python:3.6

参考

4
1
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
4
1