ビルド アーティファクトの公開とリンク

You can download your artifacts directly from the pipeline result view. If you need to access your artifacts for longer than 14 days, there is a way to send your artifacts to 3rd-party storage and create a link in your commit view, using the Bitbucket build status API.

ビルド ステータス API 経由で公開およびリンクしたアーティファクトへのリンクは、Bitbucket のコミットに表示されます。

ステップ 1: API トークンを作成する

Bitbucket API へのアクセスや Git コマンドの実行のために作成される API トークンにはスコープが必要です。

  1. 上部ナビゲーション バーの右上隅にある [設定] 歯車アイコンを選択します。

  2. [個人設定] で [Atlassian アカウント設定] を選択します。

  3. 上部のナビゲーション バーの [セキュリティ] タブを選択します。

  4. [API トークンの作成と管理] を選択します。

  5. [スコープ付き API トークン作成] を選択します。

  6. API トークンに名前と有効期限を指定し (通常は、トークンを使用するアプリに関連するものを指定する)、[次へ] を選択します。

  7. アプリとして [Bitbucket] を選択し、[次へ] を選択します。

  8. Select the scopes (permissions) the API token needs and select Next. For detailed descriptions of each permission, see: API Token permissions. Note: This step is required for your API token to access Bitbucket APIs or perform Git commands.

  9. トークンを確認し、[トークンを作成] ボタンを選択します。ページに新しい API トークンが表示されます。

  10. 生成された API トークンをコピーして、記録するか、アクセス権を付与するアプリに貼り付けます。

トークンは一度だけ表示され、後から取得することはできません。

手順 2: 認証トークンを使用して Pipelines 変数を作成する

Pipelines の変数設定で、次のようにセキュアな変数を新規に定義します。

  • ATLASSIAN_ACCOUNT_EMAIL:your_email@example.com

  • ATLASSIAN_API_TOKEN:TOKEN_VALUE_FROM_STEP_1

この変数は、リポジトリまたはアカウント レベルで定義できます。

ステップ 3: アーティファクトを AWS に公開する

If you are new to AWS or S3, follow the instructions on our example S3 integration to create an S3 bucket and configure the relevant authentication variables in Bitbucket Pipelines.

python s3_upload.py <bucket-id> <artifact-file> <artifact-key>

既存の AWS ツールを使用してアーティファクトを適切なロケーションにアップロードすることもできます。

With the variables in place and your artifact published to S3, you can now use curl in your build script to link your artifact's S3 URL to your Bitbucket commit via the build status REST API:

export S3_URL="https://${S3_BUCKET}.s3.amazonaws.com/${S3_KEY_PREFIX}_${BITBUCKET_COMMIT}" export BUILD_STATUS="{\"key\": \"doc\", \"state\": \"SUCCESSFUL\", \"name\": \"Documentation\", \"url\": \"${S3_URL}\"}" curl -H "Content-Type: application/json" -X POST --user "${ATLASSIAN_ACCOUNT_EMAIL}:${ATLASSIAN_API_TOKEN}" -d "${BUILD_STATUS}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/commit/${BITBUCKET_COMMIT}/statuses/build"

bitbucket-pipelines.yml の例

Python のサンプル プロジェクトのすべての構成要素を含む例について、以降に示します。この例のパラメーターは自身のリポジトリに合わせて調整する必要があります。また、必要なすべての変数 (AWS 認証トークンを含む) を定義済みである必要があります。

bitbucket-pipelines.yml

image: python:3.5.1 pipelines: branches: main: - step: script: - pip install boto3==1.3.0 # required for s3_upload.py - python run_tests.py - python s3_upload.py "${S3_BUCKET}" documentation.html "${S3_KEY_PREFIX}_${BITBUCKET_COMMIT}" # upload docs to S3 - export S3_URL="https://${S3_BUCKET}.s3.amazonaws.com/"${S3_KEY_PREFIX}_${BITBUCKET_COMMIT}" - export BUILD_STATUS="{\"key\":\"doc\", \"state\":\"SUCCESSFUL\", \"name\":\"Documentation\", \"url\":\"${S3_URL}\"}" - curl -H "Content-Type:application/json" -X POST --user "${ATLASSIAN_ACCOUNT_EMAIL}:{$ATLASSIAN_API_TOKEN}" -d "${BUILD_STATUS}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/commit/${BITBUCKET_COMMIT}/statuses/build"

You can check your bitbucket-pipelines.yml file with our online validator.

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

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