> 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/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-bitbucket-pipelines.md).

# Bitbucket Pipelines での Device Protection

Bitbucket Pipelines のステップは Linux 上で実行されるため、Device Protection のインストールは任意の Linux マシンと同じ方法で行われます。Bitbucket で特有なのは、インストール先です。永続する Linux Shell ランナー上で 1 回だけ行うか、Bitbucket Cloud と Docker ランナーでは各ステップ内で行うかです。

まず [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md) トークンとインストール方式についてお読みください。以下のジョブレベルのスニペットでは container 方式を使用しており、これは [コンテナ内の Device Protection](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-containers.md) を説明しています。

## Bitbucket Cloud と Docker ランナー

Device Protection トークンを、という名前の保護されたリポジトリ変数として追加してください `AIKIDO_TOKEN`。次に、このスクリプトをリポジトリに追加してください:

{% code title="ci/start-device-protection.sh" overflow="wrap" %}

```bash
curl -fsSL https://github.com/AikidoSec/safe-chain/raw/refs/heads/main/install-scripts/install-endpoint-linux.sh | sh -s -- --container
aikido-endpoint-protection-start --wait-for-healthy
for f in /etc/profile.d/aikido-*.sh; do . "$f"; done
```

{% endcode %}

パッケージをインストールする各ステップの先頭で source してください:

{% code title="bitbucket-pipelines.yml" overflow="wrap" %}

```yaml
image: node:20-bookworm

pipelines:
  default:
    - step:
        name: 依存関係をインストール
        script:
          - . ci/start-device-protection.sh
          - npm ci
```

{% endcode %}

* **次のように source してください `.`、次の方法で実行しないでください `sh`.** source すると、そのステップの残りの間設定が保持されます。
* **各ステップで必要です。** 各ステップは新しいコンテナです。
* **ステップは root として実行する必要があり、イメージには `curl`.**

## Linux Shell ランナー

runner ホストにエージェントを `--headless`付きでインストールし、その後再起動します。参照: [Linux 用 Device Protection をインストールする](/docs/docs-ja/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/install-device-protection-for-linux.md#choose-the-install-flavor).

## 動作確認

{% code title="bitbucket-pipelines.yml" overflow="wrap" %}

```yaml
    - step:
        name: Device Protection を検証
        script:
          - . ci/start-device-protection.sh
          - curl -sS -o /dev/null -w "%{http_code}\n" --max-time 15 https://registry.npmjs.org/safe-chain-test/-/safe-chain-test-0.0.1-security.tgz
```

{% endcode %}

`403` は、エージェントがマルウェアのテスト用パッケージをブロックしたことを意味します。 `200` は、ダウンロードがエージェントを回避したことを意味します。

## トラブルシューティング

| 問題                                                | 修正                                                         |
| ------------------------------------------------- | ---------------------------------------------------------- |
| `トークンが必要です`                                       | ステップからその変数が見えません。名前を確認してください                               |
| `root 権限が必要です`                                    | イメージは non-root ユーザーで実行されます。root で実行されるものを使用してください          |
| テストパッケージが返す `200`、または `SELF_SIGNED_CERT_IN_CHAIN` | スクリプトは次の設定で実行されました `sh` または `bash`。次のように source してください `.` |


---

# 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/aikido-device-protection/deploying-aikido-endpoint/device-protection-mdm-guides/linux/device-protection-in-bitbucket-pipelines.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.
