> For the complete documentation index, see [llms.txt](https://help.aikido.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.aikido.dev/docs/docs-ja/pr-torirsugtingu/bitbucket-pr-gating/bitbucket-pipes-setting-up-gating-for-pull-requests-via-code.md).

# Bitbucket Pipes: コード経由でプルリクエストのゲーティングを設定する

> この機能の使用はもう推奨しません。代わりに Aikido Dashboard での PR gating を使用してください。CI 分を消費せず、一括管理もしやすく、エラーも起こりにくいためです。

Aikido の Bitbucket Pipes との連携により、リスクの高いコードがマージされるのをフラグ付けしたりブロックしたりできます。私たちの CI スキャンの対象は **IaC**, **SAST**、および **依存関係の問題**.

Aikido の Bitbucket Pipes 用連携を使って、Bitbucket のワークフローに Aikido を統合しましょう。私たちの [Bitbucket Pipe のソースコードはこちらです。](https://bitbucket.org/aikido-production/bitbucket-pipe/src)

## 前提条件 <a href="#prerequisites" id="prerequisites"></a>

### リポジトリで pipelines を有効にする <a href="#enable-pipelines-in-your-repositories" id="enable-pipelines-in-your-repositories"></a>

連携を有効にするには、まず Bitbucket で保護したいリポジトリで pipelines が有効になっていることを確認する必要があります。これを行うには、次の手順に従ってください：

1. Bitbucket アカウントにログインします
2. pipelines を有効にしたいリポジトリに移動します
3. 左側のナビゲーションで「Repository settings」をクリックします
4. 左側のナビゲーションを「Pipelines」セクションまでスクロールし、「Settings」をクリックします
5. pipelines を有効にする

![自動ビルド用に Pipelines が有効になっている Bitbucket リポジトリ設定。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-d5f8b1c50ee11384d70d7dfa23e41fd1fc714d67%2Fucarecdn-95d9dbd1-ca3b-4dd2-806c-41577276cb35.png?alt=media)

### Aikido CI 連携トークンを取得する <a href="#obtain-your-aikido-ci-integration-token" id="obtain-your-aikido-ci-integration-token"></a>

次に、Aikido の CI 連携があなたの Aikido アカウントに接続できるようにする必要があります。これは、Aikido アカウントで生成できる秘密の認証トークンを使って行います。

1. 当社の [CI Integrations ページ](https://app.aikido.dev/settings/integrations/continuous-integration).
2. 認証トークンを生成します。連携のために、これを CI 環境で使用できるようにする必要があります。トークンを必ずコピーして、安全な場所に保管してください。次の手順で必要になります。
3. Bitbucket Pipes をクリックします。\
   ​

![GitHub、GitLab、または Bitbucket に接続するためのトークンを生成する CI 連携ページ。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-ebebe79d90500091985edd01280bb2071c11fd27%2Fucarecdn-0330325f-82c1-4f99-a2d3-d20b2ee8c36a.png?alt=media)

## リポジトリで連携を設定する <a href="#configuring-the-integration-in-your-repo" id="configuring-the-integration-in-your-repo"></a>

最後に、認証トークンを pipelines で使用できるようにし、連携を実行する設定ファイルを作成します。

1. Bitbucket アカウントのリポジトリ設定に移動します
2. 左側のナビゲーションを「Pipelines」セクションまでスクロールし、「Repository variables」をクリックします
3. 前の手順で取得した認証トークンをリポジトリ変数として追加します。この記事では、これを `AIKIDO_API_KEY`と名付けますが、好きな名前で構いません。
4. 次の設定はオンのままにすることを推奨します。 `保護` チェックボックスをオンにして、pipelines でトークンがコンソールに出力されないようにしてください。
5. 「Add」をクリックします。\
   ​

![リポジトリの設定に保護された環境変数を追加します。](https://715870456-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-bf8bbf1a647989340b3fbc8124fc81f52b565ec3%2Fucarecdn-f0c428b9-419c-4be8-9ae8-2f55b9eb1101.png?alt=media)

次に、Bitbucket pipelines にどのチェックをいつ、どこで実行するかを伝える設定ファイルを作成する必要があります。次の名前のファイルを作成してください。 `bitbucket-pipelines.yml` をリポジトリのルートに置き、次の内容を追加します。

```
pipelines:
  pull-requests:
    '**':
      - step:
          name: Aikido Security Scan
          script:
          - pipe: aikido-production/bitbucket-pipe:1.0.5
            variables:
              AIKIDO_API_KEY: $AIKIDO_API_KEY
```

この設定により、Bitbucket には次のことが伝えられます：

* 各 pull request ごとにこの pipeline を実行する
* `'**'` はフィルターで、Bitbucket に特定の pipelines のみで実行するよう指定できます。この例では、すべての pull request で実行したいと考えています
* 「Aikido Security Scan」というステップを追加し、スクリプトを実行します
* 次を実行します。 `aikido-production/bitbucket-pipe` これは、当社の公式 Bitbucket Pipelines 連携のバージョン `1.0.5`。このバージョンは、要件を満たす最新バージョンに固定しておくことを推奨します
* 次の変数を公開します： `AIKIDO_API_KEY` 前の手順で追加した環境変数を Aikido の連携環境に渡し、Aikido アカウントに接続できるようにします

公式連携は、デフォルトでは pull request の最新コミットで重大な脆弱性を見つけると失敗します。この挙動は、ほかの変数などを通じて設定可能です。以下は、現在この連携に渡して挙動を制御できる変数の概要です。

| **name**                   | **kind** | **デフォルト**  | **説明**                                                                                       |
| -------------------------- | -------- | ---------- | -------------------------------------------------------------------------------------------- |
| AIKIDO\_API\_KEY（必須）       | 文字列      | NULL       | Aikido CI 認証トークン                                                                             |
| MINIMUM\_SEVERITY          | 文字列      | 'CRITICAL' | 問題を検出したときに失敗させる重大度です。'CRITICAL'、'HIGH'、'MEDIUM'、'LOW' のいずれかにできます                             |
| FAIL\_ON\_TIMEOUT          | 文字列      | false      | スキャンが一定時間内に完了しない場合に pipeline を失敗させるかどうかを指定します。'true' または 'false' のいずれかにできます。                 |
| FAIL\_ON\_DEPENDENCY\_SCAN | 文字列      | false      | サードパーティの依存関係の問題が検出された場合に pipeline を失敗させるかどうかを指定します。'true' または 'false' のいずれかにできます。            |
| FAIL\_ON\_SAST\_SCAN       | 文字列      | false      | SAST の問題が検出された場合に pipeline を失敗させるかどうかを指定します。'true' または 'false' のいずれかにできます。                   |
| FAIL\_ON\_IAC\_SCAN        | 文字列      | false      | Infrastructure as Code の問題が検出された場合に pipeline を失敗させるかどうかを指定します。'true' または 'false' のいずれかにできます。 |

この設定ファイルをリポジトリの main ブランチに push すると、pull request を main ブランチに同期する際に、各 push ごとに pipeline のチェックが実行されることがわかります。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.aikido.dev/docs/docs-ja/pr-torirsugtingu/bitbucket-pr-gating/bitbucket-pipes-setting-up-gating-for-pull-requests-via-code.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
