目標
例えば、 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