> 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-jenkins.md).

# Jenkins での Device Protection

Jenkins のビルドは Linux エージェント上で実行されるため、Device Protection のインストール方法は通常の Linux マシンと同じです。Jenkins 固有なのは、インストール先です。永続エージェント上に 1 回だけ入れるか、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) を説明しています。

## 永続エージェント

各 Linux エージェントホストに次を使ってエージェントをインストールします `--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)。パイプラインの変更は不要です。

## Docker エージェント

Device Protection トークンを次として追加します **シークレットテキスト** ID が次の資格情報として `aikido-token`を追加し、その後、パッケージをインストールする前の任意のステージでエージェントを起動します:

{% code title="Jenkinsfile" overflow="wrap" %}

```groovy
pipeline {
  agent {
    docker {
      image 'node:20-bookworm'
      args '-u root'
    }
  }
  environment {
    AIKIDO_TOKEN = credentials('aikido-token')
  }
  stages {
    stage('Start Device Protection') {
      steps {
        sh '''
          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
        '''
      }
    }
    stage('Install dependencies') {
      steps {
        sh '''
          for f in /etc/profile.d/aikido-*.sh; do . "$f"; done
          npm ci
        '''
      }
    }
  }
}
```

{% endcode %}

* **`args '-u root'` が必要です。** Jenkins はコンテナーをエージェントのユーザーとして実行するため、インストールには root が必要です。
* **ソース `/etc/profile.d/aikido-*.sh` すべての `sh` パッケージをインストールするステップで。** 各 `sh` ステップは新しいシェルであり、それらの設定がないとダウンロードはエージェントを迂回します。
* **使用 `'''`、 `"""`.** Groovy は展開します `$` ダブルクォート内で展開され、そのループを壊します。

## 動作確認

{% code title="Jenkinsfile" overflow="wrap" %}

```groovy
stage('Verify Device Protection') {
  steps {
    sh '''
      for f in /etc/profile.d/aikido-*.sh; do . "$f"; done
      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 権限が必要です`                                    | 追加 `args '-u root'` に `docker` エージェント                     |
| `トークンが必要です`                                       | 資格情報 ID と、その資格情報が **シークレットテキスト**                          |
| テストパッケージが返す `200`、または `SELF_SIGNED_CERT_IN_CHAIN` | 次の `sh` ステップは source しませんでした `/etc/profile.d/aikido-*.sh` |


---

# 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-jenkins.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.
