キャッシュ、サービス コンテナー、エクスポート パイプラインの定義
definitions
オプションでは、Bitbucket Pipelines のカスタム依存関係キャッシュとサービス コンテナー (データベース サービスを含む) を定義できます。
パイプラインのキャッシュとサービス
キャッシュとサービス コンテナーを定義するには、次のオプションを使用できます。
定義
definitions
プロパティは、パイプライン構成の別の場所で使用されるリソースを定義するために使用されます。リソースには、以下が含まれる可能性があります。
別々の Docker コンテナーで実行されるサービス – 「データベースとサービス コンテナー」をご参照ください。
キャッシュ – 「キャッシュ」をご参照ください。
YAML アンカー - yaml を分割して定義して使いやすくする方法。「YAML アンカー」を参照してください。
Property — definitions
必須 — いいえ
データ タイプ — ブロック (YAML 仕様 - ブロック マッピング)
Allowed parent properties — The YAML root (definitions
can only be a top-level property)
指定可能な子プロパティ — caches プロパティと services プロパティが 1 つ以上必要です。
例 — definitions を使用して、カスタム キャッシュとデータベース サービスをパイプライン ステップに追加する
definitions:
caches:
bundler-packages: vendor/bundle
services:
my-mariadb:
image: mariadb:latest
variables:
MARIADB_USER: $MY_MARIADB_USER
MARIADB_PASSWORD: $MY_MARIADB_PASSWORD
MARIADB_ROOT_PASSWORD: $MARIADB_ADMIN_PASSWORD
pipelines:
default:
- step:
name: Hello world example
services:
- my-mariadb
caches:
- bundler-packages
script:
- ruby -e 'print "Hello, World\n"'
例 — YAML アンカーを使用して、再利用可能なステップを作成する
definitions:
steps:
- step: &build-test
name: Build and test
script:
- mvn package
artifacts:
- target/**
pipelines:
branches:
develop:
- step: *build-test
main:
- step: *build-test
キャッシュ
Bitbucket Pipelines では、ビルドの依存関係やディレクトリのキャッシングをサポートし、ビルドの高速化と消費されるビルド時間の削減を実現しています。
定義済みのキャッシュもいくつか利用可能です。定義済みのキャッシュの完全なリストについては「 キャッシュ — 定義済みのキャッシュ」をご確認ください。
caches
オプションの使用に関する情報は、「キャッシュ」をご参照ください。
Property — caches
必須 — いいえ
データ タイプ — 改行で区切られた名前と値のペアのブロック (YAML 仕様 - ブロック マッピング)。名前はキャッシュ名、値は次のいずれかです。
ファイルまたはディレクトリ パスを表す文字列 (glob パターンを使用できます)
キャッシュ キーとパス オプションを含むノード
指定可能な親プロパティ — definitions
指定可能な子プロパティ — 次のいずれかです。
ファイルまたはディレクトリ パスを表す文字列を提供する場合: なし
If you are using the key and path options: A cache name (nested under caches)
例 — caches オプションで Ruby プロジェクト用のカスタム依存関係キャッシュを作成する
definitions:
caches:
my-bundler-cache: vendor/bundle
pipelines:
default:
- step:
caches:
- my-bundler-cache # Cache is defined above in the definitions section
script:
- bundle install --path vendor/bundle
- ruby -e 'print "Hello, World\n"'
例 — ファイル チェックサムベースのハッシュ化を用いる Ruby プロジェクト向けに、caches オプションを使用してカスタム依存関係キャッシュを作成する
key
files
オプションは、変更を監視するファイルを指定するために使用します。path
で指定されたキャッシュは、key
files
の変更に基づいてバージョン管理されます。
definitions:
caches:
my-bundler-cache:
key:
files:
- Gemfile.lock
- "**/*.gemspec" # glob patterns are supported for cache key files
path: vendor/bundle
pipelines:
default:
- step:
caches:
- my-bundler-cache # Cache is defined above in the definitions section
script:
- bundle install --path vendor/bundle
- ruby -e 'print "Hello, World\n"'
鍵 (キー)
キャッシュの key
オプションは、キャッシュの新しいバージョンをいつ作成するかを決定する基準を定義します。バージョン管理に使用されるキャッシュ キーは、files
が定義されたハッシュに基づいています。
Property — key
必須 — いいえ
Data type — Block of files
指定可能な親プロパティ — キャッシュ名 (caches の下にネストされます)
指定可能な子プロパティ — files
例 — ファイル チェックサムベースのハッシュ化を用いる Ruby プロジェクト向けに、キャッシュの key オプションを使用してカスタム依存関係キャッシュを作成する
definitions:
caches:
my-bundler-cache:
key:
files:
- Gemfile.lock
- "**/*.gemspec" # glob patterns are supported for cache key files
path: vendor/bundle
pipelines:
default:
- step:
caches:
- my-bundler-cache # Cache is defined above in the definitions section
script:
- bundle install --path vendor/bundle
- ruby -e 'print "Hello, World\n"'
キー ファイル
キャッシュ キーの files
プロパティには、変更を監視するリポジトリ内のファイルがリストされます。1 つ以上の files
のハッシュが変更されると、新しいバージョンのキャッシュが作成されます。
Property — files
必須 — はい
データ タイプ — ファイル名に一致する文字列のリスト (glob パターンを使用できます)
指定可能な親プロパティ — key
例 — ファイル チェックサムベースのハッシュ化を用いる Ruby プロジェクト向けに、キャッシュ キーの files オプションを使用してカスタム依存関係キャッシュを作成する
definitions:
caches:
my-bundler-cache:
key:
files:
- Gemfile.lock
- "**/*.gemspec" # glob patterns are supported for cache key files
path: vendor/bundle
pipelines:
default:
- step:
caches:
- my-bundler-cache # Cache is defined above in the definitions section
script:
- bundle install --path vendor/bundle
- ruby -e 'print "Hello, World\n"'
パス
キャッシュの path
オプションは、キャッシュするパスを定義します。これは、ソース リポジトリ外の場合があります。
Property — path
必須 — いいえ
データ タイプ — 文字列としてのユーザー定義のファイル パス (glob パターンを使用できます)
指定可能な親プロパティ — キャッシュ名 (caches の下にネストされます)
例 — ファイル チェックサムベースのハッシュ化を用いる Ruby プロジェクト向けに、キャッシュの path オプションを使用してカスタム依存関係キャッシュを作成する
key
files
オプションは、変更を監視するファイルを指定するために使用します。path
で指定されたキャッシュは、key
files
の変更に基づいてバージョン管理されます。
definitions:
caches:
my-bundler-cache:
key:
files:
- Gemfile.lock
- "**/*.gemspec" # glob patterns are supported for cache key files
path: vendor/bundle
pipelines:
default:
- step:
caches:
- my-bundler-cache # Cache is defined above in the definitions section
script:
- bundle install --path vendor/bundle
- ruby -e 'print "Hello, World\n"'
サービス
Bitbucket Pipelines can create separate Docker containers for services, which results in faster builds, and easy service editing. For details on creating services see Databases and service containers. This services
option is used to define the service, allowing it to be used in a pipeline step.
シークレットとログイン認証情報は、漏洩を防ぐためにユーザー定義のパイプライン変数として保存する必要があります。詳細は「変数とシークレット — ユーザー定義の変数」をご参照ください。
Property — services
必須 — いいえ
データ タイプ — ブロック (YAML 仕様 - ブロック マッピング)
指定可能な親プロパティ — definitions
指定可能な子プロパティ — ユーザー定義の文字列。この文字列はサービスの名前になります。
例 — サービス定義を使用して、データベース サービスをビルド ステップに追加する
definitions:
services:
my-service-name:
image: mariadb:latest
variables:
MARIADB_USER: $MY_MARIADB_USER
MARIADB_PASSWORD: $MY_MARIADB_PASSWORD
MARIADB_ROOT_PASSWORD: $MARIADB_ADMIN_PASSWORD
pipelines:
default:
- step:
name: Hello world example
services:
- my-service-name
script:
- echo "Hello, World"
画像
image
オプションに関する詳細 (サービスでの image
オプションの使用方法を含む) については、「Docker イメージ オプション」をご参照ください。
メモリ
memory
オプションは、サービス コンテナーで利用可能なメモリ (メガバイト単位) を制限するために使用されます。4096
MB (または size: 2x
ビルドの場合は 8192
MB) は、step
に割り当てられるメモリの総量です (スクリプトやパイプライン サービスを含む)。たとえば、サービスが 3072
MBを必要とする場合、そのサービスによるステップの実行に使用できるのは 1024
MB のみとなります。サービス コンテナーのメモリ制限に関する詳細は、「データベースとサービス コンテナー — サービス メモリの制限」をご参照ください。
Property — memory
必須 — いいえ
データ タイプ — 整数
Allowed values — From 128
to 4096
MB (or 256
to 8192
for size: 2x
builds).
Default value — 1024
指定可能な親プロパティ — サービス名 (services の下にネストされます)
例 — memory オプションを使用して、サービス コンテナーのメモリを 512MB に制限する
definitions:
services:
my-postgresql-db:
image: postgres:latest
memory: 512
variables:
POSTGRES_PASSWORD: $MY_POSTGRES_PASSWORD
pipelines:
default:
- step:
name: Hello world example
services:
- my-postgresql-db
script:
- echo "Hello, World"
タイプ
自社ホストのパイプライン ランナーのみが利用可能です。
type
オプションは、Docker サービス コンテナー (Docker-in-Docker を実行する) を指定するために使用されます。対象となるのは次のとおりです。
カスタム名の Docker-in-Docker サービス コンテナー
複数の Docker-in-Docker サービス コンテナー
詳細情報
カスタムの Docker-in-Docker サービスを追加するには、「bitbucket-pipelines.yml でランナーを設定する — Docker-in-Docker のカスタム イメージ」をご参照ください。
Docker-in-Docker サービスを使用するには、「Bitbucket Pipelines で Docker コマンドを実行する」をご参照ください。
Property — type
必須 — いいえ
データ タイプ — 文字列
Allowed values — docker
指定可能な親プロパティ — サービス名 (services の下にネストされます)
例 — type オプションを使用して、複数の Docker-in-Docker サービスを追加する
definitions:
services:
docker: # Default Docker-in-Docker service
image: docker:dind
my-docker-in-docker-name:
image: docker:latest
type: docker
docker-custom:
type: docker
image: docker:dind
pipelines:
default:
- step:
script:
- docker version
- docker run hello-world
services:
- docker
- step:
script:
- docker version
- docker run hello-world
services:
- my-docker-in-docker-name
- step:
script:
- docker version
- docker run hello-world
services:
- docker-custom
Variables
サービスの variables
オプションは、環境変数をサービス コンテナーに渡すために使用され、通常はサービスの設定に使用されます。サービスの作成方法に関する詳細については「データベースとサービス コンテナー」をご確認ください。
シークレットとログイン認証情報は、漏洩を防ぐためにユーザー定義のパイプライン変数として保存する必要があります。詳細は「変数とシークレット — ユーザー定義の変数」をご参照ください。
Property — variables
必須 — いいえ
データ タイプ — 改行で区切られた名前と値のペアのブロック (YAML 仕様 - ブロック マッピング)
指定可能な親プロパティ — サービス名 (services の下にネストされます)
例 — variables を使用して、MariaDB サービス コンテナーをセットアップする
definitions:
services:
my-service-name:
image: mariadb:latest # Official MariaDB image from DockerHub: https://hub.docker.com/_/mariadb/
variables:
MARIADB_USER: $MY_MARIADB_USER
MARIADB_PASSWORD: $MY_MARIADB_PASSWORD
MARIADB_ROOT_PASSWORD: $MARIADB_ADMIN_PASSWORD
pipelines:
default:
- step:
name: Hello world example
services:
- my-service-name
script:
- echo "Hello, World"
例 — variables を使用して、PostgreSQL サービス コンテナーをセットアップする
definitions:
services:
my-postgresql-db:
image: postgres:latest # Official PostgreSQL image from DockerHub: https://hub.docker.com/_/postgres
variables:
POSTGRES_PASSWORD: $MY_POSTGRES_PASSWORD
pipelines:
default:
- step:
name: Hello world example
services:
- my-postgresql-db
script:
- echo "Hello, World"
パイプライン - Bitbucket Premium のみ
pipelines
変数で定義されているすべてのパイプラインがエクスポートされ、同じワークスペース内の他のリポジトリによってインポートできます。
Property — pipelines
必須 — いいえ
データ タイプ — 改行で区切られた名前と値のペアのブロック (YAML 仕様 - ブロック マッピング)。名前はパイプライン名、値は pipeline です。
指定可能な親プロパティ — definitions
指定可能な子プロパティ — step、stage、または parallel プロパティが 1 つ以上必要です。
例 — export-pipeline
という名前で、1 つのステップが定義されているパイプラインをエクスポートする
export: true
definitions:
caches:
services:
pipelines:
export-pipeline:
- step:
script:
- echo hello
この内容はお役に立ちましたか?