buildspec.yaml
シーケンス | 説明 |
---|---|
version: | buildspec のバージョン(必須) |
run-as: | コマンドを実行するLinuxユーザ |
env: | 環境変数 |
proxy: | プロキシサーバ設定 |
batch: | バッチビルド設定 |
phases: | 実行するコマンド(必須) |
reports: | テストレポート出力 |
artifacts: | AWS CodeBuildの出力 |
cache: | キャッシュ設定 |
version: 0.2
run-as: Linux-user-name
env:
shell: shell-tag
variables:
key: "value"
key: "value"
parameter-store:
key: "value"
key: "value"
exported-variables:
- variable
- variable
secrets-manager:
key: secret-id:json-key:version-stage:version-id
git-credential-helper: no | yes
proxy:
upload-artifacts: no | yes
logs: no | yes
batch:
fast-fail: false | true
# build-list:
# build-matrix:
# build-graph:
phases:
install:
run-as: Linux-user-name
on-failure: ABORT | CONTINUE
runtime-versions:
runtime: version
runtime: version
commands:
- command
- command
finally:
- command
- command
pre_build:
run-as: Linux-user-name
on-failure: ABORT | CONTINUE
commands:
- command
- command
finally:
- command
- command
build:
run-as: Linux-user-name
on-failure: ABORT | CONTINUE
commands:
- command
- command
finally:
- command
- command
post_build:
run-as: Linux-user-name
on-failure: ABORT | CONTINUE
commands:
- command
- command
finally:
- command
- command
reports:
report-group-name-or-arn:
files:
- location
- location
base-directory: location
discard-paths: no | yes
file-format: report-format
artifacts:
files:
- location
- location
name: artifact-name
discard-paths: no | yes
base-directory: location
exclude-paths: excluded paths
enable-symlinks: no | yes
s3-prefix: prefix
secondary-artifacts:
artifactIdentifier:
files:
- location
- location
name: secondary-artifact-name
discard-paths: no | yes
base-directory: location
artifactIdentifier:
files:
- location
- location
discard-paths: no | yes
base-directory: location
cache:
paths:
- path
- path
version
- 0.2 を使う。
run-as
- Linux環境のみ指定可能。
- 指定しない場合、全てのコマンドがrootユーザーで実行される。
- Phasesブロックでオーバーライド可能。
env
-
環境変数
- プレーンテキスト
- parameter-store
- secrets-manager
-
環境シェル
- Linux:bash、/bin/sh
- Windows:powershell.exe、cmd.exe
proxy
- 明示的なプロキシサーバーでビルドし、アーティファクトのアップロード時、CloudWatch logsを作成する時にプロキシサーバーを利用するか指定可能。
- upload-artifacts
- logs
batch
- プロジェクトの同時実行と協調実行の定義実行を行う。
- fast-fail
build-graph
- バッチ内の他のタスクに依存する一連のタスクを定義する。
batch:
fast-fail: false
build-graph:
- identifier: build1
env:
variables:
BUILD_ID: build1
ignore-failure: false
- identifier: build2
buildspec: build2.yml
env:
variables:
BUILD_ID: build2
depend-on:
- build1
- identifier: build3
env:
variables:
BUILD_ID: build3
depend-on:
- build2
- build1 は依存関係がないため、最初に実行されます。
- build2 に依存しているbuild1、build2 実行後 build1 を完了します。
- build3 に依存しているbuild2、build3 実行後 build2 を完了します。
build-list
- 並行して実行されるタスクの数を定義するために使用される。
batch:
fast-fail: false
build-list:
- identifier: build1
env:
variables:
BUILD_ID: build1
ignore-failure: false
- identifier: build2
buildspec: build2.yml
env:
variables:
BUILD_ID: build2
ignore-failure: true
- build1 と build1 が並行して実行される。
build-matrix
- 並行して実行される異なる構成のタスクを定義する。
batch:
build-matrix:
static:
ignore-failure: false
env:
type: LINUX_CONTAINER
image: aws/codebuild/amazonlinux2-x86_64-standard:3.0
privileged-mode: true
dynamic:
buildspec:
- matrix1.yml
- matrix2.yml
env:
variables:
MY_VAR:
- VALUE1
- VALUE2
- VALUE3
- 上記の例では、matrix1/matrix2 * VALUE1/VALUE2/VALUE3 の計6つのビルドが並行して実行される。
phase
- ビルドの各段階で実行するコマンドを記述する。
- inastall:パッケージにインストールのみに利用することを推奨。runtime_versionsでランタイムを指定可能。
- pre_build:ビルド前に実行されるコマンドを記述。(例:ECRへのサインイン)
- build:ビルドで実行するコマンドを記述。
- post_build:ビルド後に実行するコマンドを記述。(ECRへのpush)
reports
- CodeBuildのジョブから出力されたレポートファイルを解析し、テスト実行結果を確認するためのビューを提供する機能。
artifacts
- アーティファクトの名、アーティファクトに含めるサブディレクトリとファイルを指定。
- secondary-artifactsを利用して、複数のビルド出力アーティファクトを指定することも可能。
cache
- CodeBuildがビルドを使うときのキャッシュを定義する。
- キャッシュタイプはビルドプロジェクトに対して設定。※S3とローカルのカスタムキャッシュはbuildspec.yamlで指定する。
- キャッシュなし。
- S3
- ローカル(ソースキャッシュ、Dockerレイヤーキャッシュ、カスタムキャッシュ)
機能
- AWS CodeBuild エージェントを使用して、ローカルマシンで CodeBuild ビルドを実行してテストすることが可能。
- セッションマネージャーで実行中のビルドを表示することが可能。