キャッシュ、サービス コンテナー、エクスポート パイプラインの定義
definitions オプションでは、Bitbucket Pipelines のカスタム依存関係キャッシュとサービス コンテナー (データベース サービスを含む) を定義できます。
パイプラインのキャッシュとサービス
キャッシュとサービス コンテナーを定義するには、次のオプションを使用できます。
定義
definitions プロパティは、パイプライン構成の別の場所で使用されるリソースを定義するために使用されます。リソースには、以下が含まれる可能性があります。
Services that run in separate Docker containers – see Databases and service containers.
Caches – see Caches.
YAML anchors - a way to define a chunk of your YAML for easy re-use - see YAML anchors.
プロパティ — definitions
必須 — いいえ
Data type — Block (YAML spec - Block Mapping)
指定可能な親プロパティ — YAML ルート (definitions は必ず最上位のプロパティとなります)
Allowed child properties — Requires one or more of the caches and services properties.
例 — 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 では、ビルドの依存関係やディレクトリのキャッシングをサポートし、ビルドの高速化と消費されるビルド時間の削減を実現しています。
There are several predefined caches available. For a complete list of predefined caches, see Caches — Predefined caches.
For information on using the caches option, see Caches.
プロパティ — caches
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping), with the cache name as the name and values being either of:
A string representing the file or directory path (allows glob patterns)
キャッシュ キーとパス オプションを含むノード
Allowed parent properties — 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 オプションを使用してカスタム依存関係キャッシュを作成する
keyfiles オプションは、変更を監視するファイルを指定するために使用します。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 が定義されたハッシュに基づいています。
プロパティ — key
必須 — いいえ
データ タイプ — files のブロック
Allowed parent properties — A cache name (nested under caches)
Allowed child properties — 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 のハッシュが変更されると、新しいバージョンのキャッシュが作成されます。
プロパティ — files
必須 — はい
Data type — List of Strings matching file names (allows glob patterns)
Allowed parent properties — 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 オプションは、キャッシュするパスを定義します。これは、ソース リポジトリ外の場合があります。
プロパティ — path
必須 — いいえ
Data type — User-defined file path as String (allows glob patterns)
Allowed parent properties — A cache name (nested under caches)
例 — ファイル チェックサムベースのハッシュ化を用いる Ruby プロジェクト向けに、キャッシュの path オプションを使用してカスタム依存関係キャッシュを作成する
keyfiles オプションは、変更を監視するファイルを指定するために使用します。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.
Secrets and login credentials should be stored as user-defined pipeline variables to avoid being leaked. For details, see Variables and secrets — User-defined variables.
プロパティ — services
必須 — いいえ
Data type — Block (YAML spec - Block Mapping)
Allowed parent properties — 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"画像
For details on the image options, including using the image options for services, see Docker image options.
メモリ
The memory option is used to limit the memory (in megabytes) available to a service container. 4096MB (or 8192 MB for size: 2x builds) is the total amount of memory that can be allocated to a step, including scripts and pipeline services. For example: if a service requires 3072MB, then only 1024MB is available to run steps using that service. For details on service container memory limits see Databases and Service Containers — Service memory limits.
プロパティ — memory
必須 — いいえ
データ タイプ — 整数
指定可能な値 — 128 ~ 4096 (size: 2x ビルドの場合は 256 ~ 8192) MB。
既定値 — 1024
Allowed parent properties — A service name (nested under 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"タイプ
Only available for self-hosted pipeline runners.
type オプションは、Docker サービス コンテナー (Docker-in-Docker を実行する) を指定するために使用されます。対象となるのは次のとおりです。
カスタム名の Docker-in-Docker サービス コンテナー
複数の Docker-in-Docker サービス コンテナー
詳細情報
Adding custom Docker-in-Docker services, see Configure your runner in bitbucket-pipelines.yml — Custom docker-in-docker image.
Using a Docker-in-Docker service, see Run Docker commands in Bitbucket Pipelines.
プロパティ — type
必須 — いいえ
データ タイプ — 文字列
指定可能な値 — docker
Allowed parent properties — A service name (nested under 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-customVariables
The services variables option is used to pass environmental variables to service containers, typically used to configure the service. For details on creating services see Databases and service containers.
Secrets and login credentials should be stored as user-defined pipeline variables to avoid being leaked. For details, see Variables and secrets — User-defined variables.
プロパティ — variables
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping)
Allowed parent properties — A service name (nested under 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 変数で定義されているすべてのパイプラインがエクスポートされ、同じワークスペース内の他のリポジトリによってインポートできます。
プロパティ — pipelines
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping), with the pipeline name as the name and values being pipeline
Allowed parent properties — definitions
Allowed child properties — Requires one or more of the step, stage, or parallel properties.
例 — export-pipeline という名前で、1 つのステップが定義されているパイプラインをエクスポートする
export: true
definitions:
caches:
services:
pipelines:
export-pipeline:
- step:
script:
- echo helloこの内容はお役に立ちましたか?