Bitbucket is getting a new navigation

We’re rolling out these changes, so the documentation may not match your experience in the Bitbucket Cloud app. Read about the new Bitbucket navigation

ビルド システムを Bitbucket Cloud と連携する

 

ビルド システムやベンダーが Bitbucket Cloud と既に連携している可能性があります。連携済みの場合は、ビルドをトリガーする各コミットでビルドのステータスを確認できます。

ビルドのステータスが表示されない場合、ビルド ツールでスクリプトを実行できるのであれば、ビルドを独自に連携できます。連携するには、Bitbucket でコミットを更新するビルドの最後の手順の後にスクリプトを追加します。

次の Python スクリプトは、最後のビルド ステップとして追加する処理の例を提供します。このスクリプトは、ツールの更新が環境変数に基づくのか、スクリプト内で手動で入力できるかに応じて、次のフィールドが含まれます。

 

フィールド

更新方法

説明

key

ビルド

ビルドのステータスを、同じコミットに関連付けられた他のステータスと区別するキー。スクリプトでは、例として BUILD_ID を使用します。

state

ビルド、またはスクリプト内で手動

コミットのステータスを示します。スクリプトはビルドの後に実行されるため、スタータスは SUCCESSFUL または FAILED のいずれかとなります。

ビルド システムに応じて、ステータスを提供する環境変数を使用するか、ビルドの出力内容に応じて (既に含まれるステータスを使用して) 実行される 2 つの個別スクリプトを作成することができます。

name

ビルド

ビルドの名前。スクリプトでは、例として JOB_NAME を使用します。

url

ビルド

ビルドの詳細が記載されたページへの URL。スクリプトでは、例として BUILD_URL を使用します。

description

ビルド、またはスクリプト内で手動

ビルドの説明。お使いのビルド システムに応じて、説明を提供するための環境変数を使用するか、実行前にスクリプトに説明を追加できます。スクリプトは、例として The build passed. を使用します。

owner

スクリプト内で手動

リポジトリ オーナーのアカウント。スクリプトでは、例として emmap1 を使用します。

For more information about the api_url, see the statuses/build Resource.

repo_slug

スクリプト内で手動

リポジトリ名。スクリプトでは、例として MyRepo を使用します。

For more information about the api_url, see the statuses/build Resource.

revision

ビルド

コミットの SHA1 値とビルドのステータス。スクリプトでは、例として GIT_COMMIT を使用します。

For more information about the api_url, see the statuses/build Resource.

auth

スクリプト内で手動

認証情報。ユーザー名とパスワードを入力できます。リポジトリがワークスペースの一部である場合、ユーザー名とパスワードの組み合わせ、またはワークスペース名と API キーを入力できます。スクリプトでは、例として auth_user および auth_password を使用します。

ビルドの最後のスクリプトの例

#!/usr/bin/env python import os import requests # Use environment variables that your CI server provides to the key, name, # and url parameters, as well as commit hash. (The values below are used by # Jenkins.) data = { 'key': os.getenv('BUILD_ID'), 'state': 'SUCCESSFUL', # or 'FAILED' for a script that runs when the build fails 'name': os.getenv('JOB_NAME'), 'url': os.getenv('BUILD_URL'), 'description': 'The build passed.' } # Construct the URL with the API endpoint where the commit status should be # posted (provide the appropriate owner and slug for your repo). api_url = ('https://api.bitbucket.org/2.0/repositories/' '%(owner)s/%(repo_slug)s/commit/%(revision)s/statuses/build' % {'owner': 'emmap1', 'repo_slug': 'MyRepo', 'revision': os.getenv('GIT_COMMIT')}) # Post the status to Bitbucket. (Include valid credentials here for basic auth. # You could also use team name and API key.) requests.post(api_url, auth=('auth_user', 'auth_password'), json=data)

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。