Bitbucket Cloud の使用を開始する
Bitbucket Cloud を初めてお使いですか? 新規ユーザー用のガイドをご利用ください。
Bitbucket を使用すると、複数のパイプラインを手動でトリガーするか、特定の時間にトリガーをスケジュールすることで、複数のパイプラインを実行できます。
次のチュートリアルでは、手動パイプラインをトリガーする方法、またはトリガーをスケジュールする方法を学びます。
Pipelines のトリガーには次の制限があります。
手動ステップにより、手動でトリガーされたときにのみ実行されるステップを構成して、CI/CD パイプラインをカスタマイズできます。これは、ステップの実行前に手動でのテストやチェックが必要になる、デプロイ ステップなどの項目で便利です。
Configure a manual step by adding trigger: manual to the step in your bitbucket-pipelines.yml file.
パイプラインはコミットでトリガーするため、最初のステップを手動にすることはできません。パイプラインを手動でのみ実行したい場合、カスタム パイプラインをセットアップできます。カスタム パイプラインのもう 1 つのメリットは、変数の値を一時的に追加または更新できる点です。バージョン番号を追加したり、1 回のみ使用する値を提供したりするために使用できます。
特定のコミットに対して既存のパイプラインを手動で実行したり、既存のパイプラインをスケジュールされたビルドとして手動で実行したりすることができます。
パイプラインを手動でのみ実行したい場合、カスタム パイプラインを使用します。カスタム パイプラインは、ブランチへのコミットでは自動的に実行されません。カスタム パイプラインを定義するには、bitbucket-pipelines.yml ファイルの custom セクションにパイプライン構成を追加します。カスタム パイプラインとして定義されていないパイプラインは、ブランチへのプッシュが発生したときに自動的に実行されます。
パイプラインを手動で実行し、Bitbucket Cloud UI からトリガーするには、リポジトリでの書き込み権限が必要です。
パイプラインを bitbucket-pipelines.yml ファイルに追加します。bitbucket-pipelines.yml ファイルに含まれるあらゆるパイプライン ビルド構成について、ビルドを手動でトリガーできます。ファイルを編集します。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pipelines:
custom: # Pipelines that can only be triggered manually
sonar:
- step:
script:
- echo "Manual triggers for Sonar are awesome!"
deployment-to-prod:
- step:
script:
- echo "Manual triggers for deployments are awesome!"
branches: # Pipelines that run automatically on a commit to a branch can also be triggered manually
staging:
- step:
script:
- echo "Automated pipelines are cool too."
Bitbucket Cloud からパイプラインをトリガーします。パイプラインは、Bitbucket Cloud のブランチ ビューまたはコミット ビューから手動でトリガーできます。
ブランチ ビューからパイプラインを手動で実行する
Bitbucket でリポジトリを選択し、[ブランチ] に移動します。
パイプラインを実行するブランチを選択します。
(...) をクリックし、[ブランチでパイプラインを実行] をクリックします。
パイプラインを選択して [実行] をクリックします。
コミット ビューからパイプラインを手動で実行する
Bitbucket でリポジトリを選択し、[コミット] に移動します。
コミット ビューに移動してコミットを表示します。
コミット ハッシュを選択します。
[パイプラインの実行] を選択します。
パイプラインを選択して [実行] をクリックします。
Pipelines ページからパイプラインを手動で実行
Bitbucket でリポジトリを選択し、[Pipelines] に移動します。
[パイプラインの実行] をクリックします。
ブランチ、パイプラインを選択して [実行] をクリックします。
さらに、カスタム パイプラインを実行して、パイプラインに変数を手動でパースできます。
変数を有効化するには、パイプラインを実行するときに入力するカスタム パイプラインの下に変数を定義します。
例:
1
2
3
4
5
6
7
8
9
10
pipelines:
custom:
custom-name-and-region: #name of this pipeline
- variables: #list variable names under here
- name: Username
- name: Region
- step:
script:
- echo "User name is $Username"
- echo "and they are in $Region"
[Branches] > [⋯] > [ブランチでパイプラインを実行] > [カスタム] に移動して、カスタム パイプラインを実行します。
スケジュールされたパイプラインを使用すると、パイプラインを時間、日、または週単位で実行できます。
スケジュールされたパイプラインは、コミットや手動操作でトリガーされるあらゆるビルドに追加して実行できます。
bitbucket-pipelines.yml ファイルで定義したすべてのパイプラインにスケジュールを作成できます。
カスタム パイプラインを作成した場合、それはスケジュールされたときまたは手動でトリガされたときにのみ実行されます。
パイプラインの作成
Here's a simple example showing how you would define a custom pipeline in the bitbucket-pipelines.yml file.
例:
1
2
3
4
5
6
pipelines:
custom: # defines that this can only be triggered manually or by a schedule
staging: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Scheduled builds in Pipelines are awesome!"
カスタム パイプラインの詳細については、こちらをお読みください。
パイプラインのスケジュールを作成する
Bitbucket のリポジトリに移動します。
[パイプライン] > [スケジュール] (右上) の順に移動して [新規スケジュール] をクリックします。
スケジュールを登録したいブランチとパイプラインを選択します。
スケジュール実行は、ブランチの HEAD コミットを実行します。
選択したブランチの bitbucket-pipelines.yml でパイプラインが定義されている必要があります。
スケジュールを設定します。
パイプラインの実行間隔を選択します (時間、日、または週単位)。
ご利用のタイムゾーンで時間を選択します。パイプラインは UTC 時刻でスケジュールされます (夏時間の影響は受けません)。
スケジュールされたパイプラインは、選択した期間内の任意のタイミングで実行されます。これは、その期間にスケジュールされたパイプラインのトリガーを分散させるためです。
[パイプライン] > [スケジュール] (画面右上の) に移動して、リポジトリのすべてのスケジュールを確認します。
スケジュールの右側にあるゴミ箱アイコンを使用してスケジュールを削除します。
Note that schedules created using the API are displayed as a Cron expression (such as 0 10 15 * *).
You can change what your pipeline does depending on which branch you push to. All you need is some branch-specific configuration in your bitbucket-pipelines.yml file.
「bitbucket-pipelines.yml を設定する」も参照してください。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
image: node:10.15.0
pipelines:
default:
- step:
script:
- echo "This script runs on all branches that don't have any specific pipeline assigned in 'branches'."
branches:
main:
- step:
script:
- echo "This script runs only on commit to the main branch."
feature/*:
- step:
image: openjdk:8 # This step uses its own image
script:
- echo "This script runs only on commit to branches with names that match the feature/* pattern."
この例は、main ブランチに基づく 2 つのブランチを示します。
フィーチャー ブランチである、feature/BB-123-fix-links という名前のブランチ。
チームがまったく新しいものを自由に開発できる場である、 experimental という名前のブランチ。このブランチは feature ブランチではありません。
各ブランチのルート ディレクトリに、同じ bitbucket-pipelines.yml ファイルがあります。ブランチにプッシュするたびに、Pipelines では bitbucket-pipelines.yml file ファイルでブランチに割り当てられたスクリプトが実行されます。
main ステップの定義には、main へのコミットで実行する命令が含まれています。
feature/* 定義には、任意の feature ブランチ (ここでは BB-123-fix-links ブランチ) へのコミットで実行される命令が含まれています。
default の定義には、main または feature 以外の任意のブランチ (ここでは experimental ブランチ) へのコミットで実行される命令が含まれています。
ブランチのパイプラインは、ブランチに対する bitbucket-pipelines.yml ファイルの要件が満たされている場合にのみトリガーされることに注意してください。
If you ever want to push a commit and skip triggering its pipeline, you can add [skip ci] or [ci skip] to the commit message.
既定のブランチ: 他のセクションのパイプライン定義に一致しないすべてのブランチのパイプライン定義が含まれます。default パイプラインは、ブランチ固有のパイプラインが定義されている場合を除き、リポジトリへのプッシュのたびに実行されます。ブランチ パイプラインは branch セクションで定義できます。
注: default パイプラインはタグまたはブックマークでは実行されません。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
pipelines:
default:
- parallel:
- step:
name: 'Build and Test'
script:
- echo "Your build and test goes here..."
- step:
name: 'Lint'
script:
- echo "Your linting goes here..."
- step:
name: 'Security scan'
script:
- echo "Your security scan goes here..."
- step:
name: 'Deployment to Staging'
deployment: staging
script:
- echo "Your deployment to staging script goes here..."
- step:
name: 'Deployment to Production'
deployment: production
trigger: 'manual'
script:
- echo "Your deployment to production script goes here..."
tags - すべてのタグ固有のビルド パイプラインを定義します。このセクションの名前または表現は、Git リポジトリのタグや注釈付きタグと照合されます。
例:
このタグは、「release-」で始まるタグがプッシュされたときにパイプラインをトリガーします。
1
2
3
4
5
6
pipelines:
tags:
release-*:
- step:
script:
- echo "A tag triggered build"
pull-requests - リポジトリから開始されたプル リクエストでのみ実行される特別なパイプラインです。実行前に宛先ブランチを作業ブランチにマージします。フォークされたリポジトリからのプル リクエストは、パイプラインをトリガーしません。マージが失敗すると、パイプラインが停止します。
プル リクエスト パイプラインは定義されている任意のブランチおよびデフォルト パイプラインに加えて実行されるため、定義が重複すると 2 つのパイプラインが同時に実行される場合があります。
If you already have branches in your configuration, and you want them all to only run on pull requests, replace the keyword branches with pull-requests.
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pipelines:
pull-requests:
'**': #this runs as default for any branch not elsewhere defined
- step:
script:
- ...
feature/*: #any branch with a feature prefix
- step:
script:
- ...
branches: #these will run on every push of the branch
staging:
- step:
script:
- ...
custom - Bitbucket Cloud インターフェイスから手動またはスケジュール実行でのみトリガーできるパイプラインを定義します。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
image: node:10.15.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 "Auto pipelines are cool too."
上記のような構成の場合、Bitbucket Cloud の [パイプラインの実行] ダイアログに次のパイプラインが表示されます。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
image: node:10.15.0
pipelines:
default:
- step:
name: Build and test
script:
- npm install
- npm test
tags: # add the 'tags' section
release-*: # specify the tag
- step: # define the build pipeline for the tag
name: Build and release
script:
- npm install
- npm test
- npm run release
branches:
staging:
- step:
name: Clone
script:
- echo "Clone all the things!"
variables - (カスタム パイプラインのみ) パイプラインの起動時に提供される変数が含まれます。変数を有効にするには、パイプラインを実行するときに入力するカスタム パイプラインの下に変数を定義します。変数を有効化するには、パイプラインを実行するときに入力するカスタム パイプラインの下に変数を定義します。
例:
1
2
3
4
5
6
7
8
9
10
pipelines:
custom:
custom-name-and-region: #name of this pipeline
- variables: #list variable names under here
- name: Username
- name: Region
- step:
script:
- echo "User name is $Username"
- echo "and they are in $Region"
[ブランチ] > [...] > [ブランチのパイプラインを実行] > [カスタム] でカスタム パイプラインを実行すると、それらを渡すことができます。
キーワード variables は、サービスの定義の一部にすることもできます。
bookmarks: すべてのブックマーク固有のビルド パイプラインを定義します。このセクションの名前または表現は、Mercurial リポジトリのブックマーク名に照合されます。
例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
image: node:10.15.0
pipelines:
default:
- step:
name: Build and test
script:
- npm install
- npm test
bookmarks: # add the 'bookmarks' section
release-*: # specify the bookmark
- step: # define the build pipeline for the bookmark
name: Build and release
script:
- npm install
- npm test
- npm run release
branches:
staging:
- step:
name: Clone
script:
- echo "Clone all the things!"
glob パターンでは、アスタリスクで始まる表現は使用できません。アスタリスクで始まる表現は、引用符で囲む必要があります。
feature/* |
|
feature/bb-123-fix-links |
|
" * " |
|
" ** " |
|
" */feature " |
|
' main ' および重複するブランチ名 |
|
この内容はお役に立ちましたか?