基礎 | CircleCI
- 公式リファレンス
- 設定ファイル
- config.yml Keyリファレンス
- ワークフロー
- ワーキングディレクトリ
- CircleCI Yaml syntax アンカー(&)、エイリアス(*)、Merge(«)
Ref
- 設定ファイルの概要
- 日本語のコード部分は不備があるので英語版を参照
https://circleci.com/docs/2.0/config-intro/?section=configuration
- 日本語のコード部分は不備があるので英語版を参照
- CircleCI を設定する
- https://circleci.com/docs/ja/2.0/writing-yaml/ (YAML)
- https://circleci.com/docs/2.0/add-ssh-key/ (SSH KEY)
orbは「球」「天体」という意味の英単語ですが、CircleCIにおける Orb は再利用可能な設定パッケージを指す用語です。
設定ファイル
.circleディレクトリにconfig.ymlを作成する。
config.yml Keyリファレンス
config.yml ファイルで使用される CircleCI 2.x 構成キーのリファレンス ガイドです。
- https://circleci.com/docs/ja/2.0/configuration-reference/?section=configuration (リファレンス)
上記は実際のファイルのインデントに沿って記載されている。
実行環境の概要
https://circleci.com/docs/ja/executor-intro/
上記がとてもわかり易い。
各ジョブでdockerやmachineプロパティで定義できる。
また共通して使用するものをexecutorsプロパティで定義することで、使い回すこともできる。
orbの実行環境
例えばcircleci/aws-ecr@8.2.1の実行環境のデフォルトExecutorはここに記載されている。
各ジョブにdocker、machineなどでExecutorを設定していない場合はデフォルトのExecutorが使用される。
パラメータ変数
https://circleci.com/docs/2.0/pipeline-variables/#pipeline-parameters-in-configuration
steps
https://circleci.com/docs/ja/2.0/configuration-reference/?section=configuration#steps
# 基本形式
# ...
steps:
- run:
name: テストの実行
command: echo "Hello World"
# 省略形式
steps:
- run: echo "Hello World"
checkoutなどビルトインのstep例。
steps:
- checkout
ワークフロー
CircleCI のワークフロー モデルは、先行ジョブのオーケストレーションに基づいています。
https://circleci.com/docs/ja/2.0/config-intro/?section=configuration
ワーキングディレクトリ
/home/circleci/projectstepsを実行するディレクトリでありconfig.ymlでの./は↑checkoutは↑に配置run: pwdで確認できるworking_directoryで変更可能
CircleCI Yaml syntax アンカー(&)、エイリアス(*)、Merge(«)
- アンカー(
&)は、スカラー・マップ・シーケンス(リスト)のいずれに対しても付けられる - エイリアス(
*)単体で参照・複製できるのはスカラー値(文字列や数値など)のみ - マップやシーケンスを複製・結合したい場合は、単なるエイリアスではなく
<<(マージキー)でエイリアスを注入する - ただし
<<でマージできるのはマップのみで、シーケンス(配列/リスト)はマージできない
ref.
- https://circleci.com/docs/ja/introduction-to-yaml-configurations/#anchors-and-aliases
Merge
マップとは
キー: 値
Mergeの例
common: &common
common_steps:
- a
- b
sample1:
<<: *common
own_steps:
- c
- d
sample2:
<<: *common
own_steps:
- e
- f
{
"sample1": {
"own_steps": [
"c",
"d"
],
"common_steps": [
"a",
"b"
]
},
"common": {
"common_steps": [
"a",
"b"
]
},
"sample2": {
"own_steps": [
"e",
"f"
],
"common_steps": [
"a",
"b"
]
}
}
ref. https://circleci.com/ja/blog/what-is-yaml-a-beginner-s-guide/
- https://stackoverflow.com/questions/41063361/what-is-the-double-left-arrow-syntax-in-yaml-called-and-wheres-it-specced
- https://yaml.org/type/merge.html
- https://github.com/yaml/yaml/issues/35#issuecomment-457331385