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 ダウンロードにビルド アーティファクトをデプロイする

Bitbucket API トークンと Bitbucket REST API を使用すると、パイプラインによって生成されたアーティファクトを Bitbucket Downloads にデプロイできます。

See also Test with databases in Bitbucket Pipelines.

ステップ 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 変数を作成する

Bitbucket Downloads にファイルをアップロードするには、以下の変数を設定する必要があります。

パラメーター

ATLASSIAN_ACCOUNT_EMAIL

リポジトリ所有者 (および成果物をアップロードするユーザー) の Atlassian アカウントのメール アドレス

ATLASSIAN_API_TOKEN

アトラシアンが生成する API トークン

リポジトリの設定で、特定のデプロイメント環境に対してこれらの変数を定義できます。[リポジトリ設定] > パイプライン下の [リポジトリ変数] を選択します。

結果

リポジトリでこれら 2 つの変数が構成され、パイプラインから使用する準備ができました。

ステップ 3a: bitbucket-upload-file パイプを使用したアーティファクトのデプロイ

Use bitbucket-upload-file pipe to upload your artifact to Bitbucket Downloads. You just need to reference the file you want to upload from your build output. 

hello world Go アプリを作成し、コンパイルされたバイナリを構築してアップロードする一例をご紹介します。

bitbucket-pipelines.yml

image: golang:1.25.0 pipelines: default: - step: name: Create hello world go app artifacts: - main.go script: - | cat > main.go << 'EOF' package main func main() { println("Hello, World!") } EOF - step: name: Build artifacts: - compiled_app script: - go build -o compiled_app main.go - step: name: Upload script: - pipe: atlassian/bitbucket-upload-file:0.7.5 variables: ATLASSIAN_ACCOUNT_EMAIL: $ATLASSIAN_ACCOUNT_EMAIL ATLASSIAN_API_TOKEN: $ATLASSIAN_API_TOKEN FILENAME: "compiled_app"

結果

上記の構成の bitbucket-pipelines.yml ファイルをリポジトリのルートに配置する必要があります。ステップが完了すると、アーティファクトはリポジトリの Downloads セクションにアップロードされます。

ステップ 3b: curl および Bitbucket REST API を使用したアーティファクトのデプロイ

ビルド スクリプトで curl を使用して、REST API 経由でアーティファクトを Bitbucket にデプロイできます。

curl -X POST "$UPLOAD_URL" --user "$ATLASSIAN_ACCOUNT_EMAIL:$ATLASSIAN_API_TOKEN" --form files=@"/path/to/artifact.exe"

hello world Go アプリを作成して、curl によってコンパイルされたバイナリを構築してアップロードする一例をご紹介します。

bitbucket-pipelines.yml

image: golang:1.25.0 pipelines: default: - step: name: Create hello world go app artifacts: - main.go script: - | cat > main.go << 'EOF' package main func main() { println("Hello, World!") } EOF - step: name: Build artifacts: - compiled_app script: - go build -o compiled_app main.go - step: name: Upload script: - FILENAME="compiled_app" - UPLOAD_URL="https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/downloads" - curl -X POST "$UPLOAD_URL" --user "$ATLASSIAN_ACCOUNT_EMAIL:$ATLASSIAN_API_TOKEN" --form files=@$FILENAME

結果

上記の構成の bitbucket-pipelines.yml ファイルをリポジトリのルートに配置する必要があります。ステップが完了すると、アーティファクトはリポジトリの Downloads セクションにアップロードされます。

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

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

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