bitbucket-pipelines.yml を設定する

 

 

With Bitbucket Pipelines you store and manage your build configurations in a single bitbucket-pipelines.yml file. The bitbucket-pipelines.yml file can define multiple build configurations, each of which is called a 'pipeline'. The bitbucket-pipelines.yml file is structured using keywords, described below.

Bitbucket Pipelines runs pipelines using Docker containers.

なお、以下の説明もご覧ください:

First up...

 

  To start using Pipelines you must enable it in Bitbucket Cloud. You can find the guidelines in Get started with Bitbucket Pipelines.

ヒント : bitbucket-pipelines.yml ファイルは、オンボーディングプロセスで追加するか、ローカルで作成してから、構築するリポジトリのマスターブランチにプッシュします。 

 

  bitbucket-pipelines.yml ファイルの名前、配置、およびコンテンツがガイドラインに合っていることを確認してください。

名前 ファイル名はbitbucket-pipelines.yml です。
場所 ファイルの格納場所は、構築するリポジトリのルートディレクトリにする必要があります。
形式

ファイルのコンテンツは、bitbucket-pipelines.yml のガイドラインに合わせる必要があります。ガイドラインの概要は後述します。

 

  最後に、ヒントがいくつかあります。

  • bitbucket-pipelines.yml is indented only with spaces, not tabs. 
  • スペースの配置を一定にすることが重要です。一般的なことですが、bitbucket-pipelines.yml でもご注意ください (wink)
  • You can check your bitbucket-pipelines.yml file with our online validator.
  • For examples of using databases with Pipelines, see Use services and databases in Bitbucket Pipelines.

You can find the full list of limitations in Limitations of Bitbucket Pipelines.

 

概要  

We run your builds with Docker. If you don't specify an image, we'll run your build using the default image, but it's often better to specify an image that provides an environment specific to your build.

You can define the following types of pipelines in the bitbucket-pipelines.yml file:

  • default 
  • ブランチ
  • tags (Git only)
  • bookmarks (Mercurial only)
  • custom

You can start with a simple configuration for the default pipeline. This pipeline is run for all branches that don't match any other pipeline configuration and have the bitbucket-pipelines.yml file in the root directory.

You can add specific build configurations for branches, tags, and bookmarks. You can refer to branches, tags, and bookmarks in a pipeline using their name, or by using glob patterns

If you want to trigger some build pipelines manually, you can add them in the custom section.

Every pipeline can have up to 10 steps. Each step contains a script which defines the actions that should be performed to execute a build. You can override the default Docker image on each step. 

 

 

 

キーワード

Keywords are used to structure the bitbucket-pipelines.yml file that defines your build pipelines.

Keywords are unique and can't be changed. Here's a quick reference table for keywords that you can use:

 

キーワード

必須

説明

image

いいえ

A Docker image used to run your pipelines. If you don't specify the image, your pipelines run in the default Bitbucket image. You can override the main image at the step level.

max-time いいえ

The maximum time (in minutes) a step can execute for.

Use a whole number greater than 0 or less than 120. If you don't specify a max-time, it defaults to 120.

clone いいえ

Defines the depth of Git clones for all pipelines.

Use a whole number greater than zero to specify the depth. Use full for a full clone. If you don't specify the Git clone depth, it defaults to 50.

Note: This keyword is supported only for Git repositories.

pipelines

はい

Contains all your pipeline definitions.

default

いいえ

Contains the pipeline definition for all branches that don't match a pipeline definition in other sections.

ブランチ

いいえ

Contains pipeline definitions for specific Git branches and Mercurial named branches.

tags いいえ Contains pipeline definitions for specific Git tags and annotated tags.
bookmarks いいえ Contains pipeline definitions for specific Mercurial bookmarks.
custom いいえ Contains pipelines that can be triggered manually from the Bitbucket Cloud GUI.

step

はい

Defines a build execution unit. This is the set of commands that are executed on a single build agent. You can specify an image for a step (to override the default image).

trigger いいえ Specifies whether the step is manual or automatic. If you don't specify a trigger type, it defaults to automatic.

script

はい

Contains the list of commands that are executed to perform the build.

artifacts いいえ Defines files that are produced that are produced by a step, such as reports and JAR files, that you want to share with a following step.
definitions いいえ Defines resources, such as services and custom caches, that you want to use elsewhere in your pipeline configurations.

image (オプション)

Bitbucket Pipelines では、Docker コンテナを使用してビルドを実行します。

  • You can use the default image (atlassian/default-image:latest) provided by Bitbucket or define a custom image. You can specify any public or private Docker image that's not hosted on a private network. 
  • You can define images at the global or step level. You can't define an image at the branch level.

イメージを指定するには、次のように指定します。

image: <your_account/repository_details>:<tag>

For more information about using and creating images, see Use Docker images as build environments

例 

 

image: java
最新バージョンの Java のイメージを使用します。
image: java:u866
u866のバージョンの Java を使用します。
image: nodesource/node:iojs-2.0.2
バージョン iojs-2.0.2の非公式ノードバージョンを使用します。

max-time (optional)

You can define the maximum time a step can execute for (in minutes) at the global level under the options section. Use a whole number greater than zero or less than one hundred and twenty. If you don't specify a max-time, it defaults to 120.

Note: This can be overridden on a per step level using a property with the same name under a step section.

options:
  max-time: 60
pipelines:
  default:
    - step:
        script:
          - sleep 120m # This step will timeout after 60 minutes

clone (optional)

You can define the depth of clones at the global level.  Use a whole number greater than zero or use full to specify a full clone. If you don't specify the Git clone depth, it defaults to 50.

Note: This keyword is supported only for Git repositories.

If you're using the clone keyword, always specify the depth:

bitbucket-pipelines.yml
clone:
  depth: 5       # include the last five commits
 
pipelines:
  default:
    - step:
        script:
          - echo "Clone all the things!"

pipelines (必須)

The start of your build pipeline. You can build the following pipelines:

  • default 
  • branches (Git and Mercurial)
  • tags (Git)
  • bookmarks (Mercurial)

 

default (オプション)

Steps in the default pipeline are performed on all branches unless specified otherwise. You can add branch-specific configuration in the branches section.

Note: The default pipeline doesn't run on tags or bookmarks.

 

branches (オプション)

Serves as a container for all branch-specific build pipelines. The names or expressions in this section are matched against:

  • branches in your Git repository
  • named branches in your Mercurial repository

You can use glob patterns for handling the branch names.

See Branch workflows for more information about configuring pipelines to build repo branches.

 

tags (optional)

Serves as a container for all tag-specific build pipelines. The names or expressions in this section are matched against tags and annotated tags in your Git repository. You can use glob patterns for handling the tag names.

 

bitbucket-pipelines.yml
image: node:4.6.0
  
pipelines:
  default:
    - step:
        script:
          - npm install
          - npm test
  tags:                         # add the 'tags' section
    release-*:                  # specify the tag
      - step:                   # define the build pipeline for the tag
          script:
            - npm install
            - npm test
            - npm run release
  branches:
    staging:
      - step:
          script:
            - echo "Clone all the things!" 

bookmarks (optional)

Serves as a container for all bookmark-specific build pipelines. The names or expressions in this section are matched against bookmarks in your Mercurial repository. You can use glob patterns for handling the tag names.

 

bitbucket-pipelines.yml
image: node:4.6.0
  
pipelines:
  default:
    - step:
        script:
          - npm install
          - npm test
  bookmarks:                      # add the 'bookmarks' section
    release-*:                    # specify the bookmark
      - step:                     # define the build pipeline for the bookmark
          script:
            - npm install
            - npm test
            - npm run release
  branches:
    staging:
      - step:
          script:
            - echo "Clone all the things!"

custom (optional)

Serves as a container for all pipelines that can be triggered manually from the Bitbucket Cloud interface.


image: node:4.6.0
   
pipelines:
  custom: # Pipelines that are triggered manually
    sonar: # The name that is displayed in the list in the Bitbucket Cloud GUI
      - step:
          script:
            - echo "Manual triggers for Sonar are awesome!"
    deployment-to-prod: # Another display name
      - step:
          script:
            - echo "Manual triggers for deployments are awesome!"
  branches:  # Pipelines that run automatically on a commit to a branch
    staging:
      - step:
          script:
            - echo "Automated pipelines are cool too."


With a configuration like the one above, you should see the following pipelines in the 'Run pipeline' dialog in Bitbucket Cloud:



For more information, see Run pipelines manually.

 

step (必須)

Defines a build execution unit. Steps are executed in the order that they appear in the bitbucket-pipelines.yml file. You can use up to 10 steps in a pipeline.

Each step in your pipeline will start a separate Docker container to run the commands configured in the script. Each step can be configured to:

  • Use a different Docker image.
  • Configure a custom max-time.
  • Use specific caches and services.
  • Produce artifacts that subsequent steps can consume. 

Steps can be configured to wait for a manual trigger before running. To define a step as manual, add trigger: manual to the step in your bitbucket-pipelines.yml file. Manual steps:

  • Can only be executed in the order that they are configured. You cannot skip a manual step.
  • Can only be executed if the previous step has successfully completed.
  • Can only be triggered by users with "write" access to the repository.
  • Are triggered through the Pipelines web interface.

If your build uses both manual steps and artifacts, the artifacts are stored for 7 days following the execution of the step that produced them. After this time, the artifacts expire and any manual steps in the pipeline can no longer be executed. For more information, see Manual steps and artifact expiry

Note that you cannot configure the first step of the pipeline to be a manual step. 

 

trigger (optional)

Specifies whether a step will run automatically or only after being manually triggered to run by a user. You can define the trigger type as manual or automatic. If the trigger type is not defined, the step defaults to running automatically.

pipelines:
  default:
    - step:
        name: Build and test
        image: node:8.6
        script:
          - npm install
          - npm test
          - npm run build
        artifacts:
          - dist/**
    - step:
        name: Deploy
        image: python:3.5.1
        trigger: manual
        script:
          - python deploy.py

script (必須)

Contains a list of commands that are executed in sequence. Scripts are executed in the order in which they appear in a step.

  • Pipelines does not support multi-line strings, so we recommend breaking down long commands into a list of shorter commands.
  • We recommend that you move large scripts to a separate script file and call it from bitbucket-pipelines.yml

 

artifacts (optional)

Defines files to be shared from one step to a later step in your pipeline. Artifacts can be defined using glob patterns.

An example showing how to define artifacts:

pipelines:
  default:
    - step:
        name: Build and test
        image: node:8.5.0
        script:
          - npm install
          - npm test
          - npm run build
        artifacts:
          - dist/**
    - step:
        name: Deploy to production
        image: python:3.5.1
        script:
          - python deploy-to-production.py

For more information, see Using artifacts in steps.

 

definitions (optional)

Define resources used elsewhere in your pipeline configuration. Resources can include:

An example showing how to define a redis service:

definitions:
  services:
    redis:
      image: redis

An example showing how to define a custom cache:

definitions:
  caches:
    bundler: vendor/bundle

Glob patterns cheat sheet

Glob patterns don't allow any expression to start with a star. Every expression that starts with a star needs to be put in quotes.

feature/*
  • feature/<any_branch> と一致します。 
  • The glob pattern doesn't match the slash (/), so Git branches like feature/<any_branch>/<my_branch> are not matched for feature/*.
feature/bb-123-fix-links
  • If you specify the exact name of a branch, a tag, or a bookmark, the pipeline defined for the specific branch overrides any more generic expressions that would match that branch. 
  • For example, let's say that you specified a pipeline for feature/* and feature/bb-123-fix-links. On a commit to the feature/bb-123-fix-links branch Pipelines will execute steps defined for feature/bb-123-fix-links and will not execute the steps defined in feature/*.
'*'
  • Matches all branches, tags, or bookmarks. The star symbol (*) must be in single quotes.
  • This glob pattern doesn't match the slash (/), so Git branches like feature/bb-123-fix-links are not matched for '*'. If you need the slash to match, use '**' instead of '*'.
'**'
  • Matches all branches, branches, tags, or bookmarks. For example, it includes branches with the slash (/) like feature/bb-123-fix-links. The ** expression must be in quotes.
'*/feature'
  • この表現には引用符が必要です。

'master' および重複するブランチ名

  • Names in quotes are treated the same way as names without quotes. For example, Pipelines sees master and 'master' as the same branch names.  
  • 上記の場合、Pipelines では1つの名前のみ (両方ではなく、master または 'master') と一致します。
  • We recommend that you avoid duplicate names in your bitbucket-pipelines.yml file.

With Bitbucket Pipelines you store and manage your build configurations in a single bitbucket-pipelines.yml file. The bitbucket-pipelines.yml file can define multiple build configurations, each of which is called a 'pipeline'. The bitbucket-pipelines.yml file is structured using keywords, described below.

Bitbucket Pipelines runs pipelines using Docker containers.

なお、以下の説明もご覧ください:

 

最終更新日 2017 年 11 月 24 日

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する

お探しの情報が見つかりませんか?

コミュニティへの質問

Powered by Confluence and Scroll Viewport.