> 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/kdosukyan/local-code-scanning/pr-gating/azure-devops-pr-gating-using-local-scanner.md).

# ローカルスキャナーを使ったAzure DevOpsのPRゲーティング

Aikido Local Scanner は、CI パイプラインでセキュリティゲートを強制するために使用できます。

{% hint style="info" %}
クラウド接続されたワークスペース（GitHub、BitBucket など）でも PR ゲーティングを使用できます。CI をご覧ください [統合セクション](https://help.aikido.dev/section/ci-integrations/sg3q6UrIf4qE).
{% endhint %}

PR ゲーティングにより、新しいコードがデフォルトブランチにマージされる前にセキュリティ基準を満たしていることを確認できます。プルリクエストで導入された変更のみをスキャンします。スキャンで、設定した重大度しきい値以上の新しい問題が検出された場合、CI パイプラインは失敗します。

これにより、新しい脆弱性の混入を防ぎつつ、既存の検出結果は別途対応できます。

{% hint style="info" %}
また、次もサポートしています [リリースゲーティング](/docs/docs-ja/kontenaimjisukyan/local-image-scanning/release-gating-for-container-images-using-local-image-scanner.md) リリース時にチェックを強制したいチーム向けです。
{% endhint %}

PR ゲーティングを有効にするには、次を追加します `--fail-on <severity>` オプションで、希望する重大度レベルを選択します。次に、次を追加します `--gating-mode pr` オプションを追加して、PR ゲーティングを実行することを示します。また、ベース（`--base-commit-id <commit-id>`）とヘッドコミット（`--head-commit-id <commit-id>`）を指定する必要があります。ベースコミット ID に対して以前にスキャンが実行されている場合、スキャン結果はその結果と比較されます。そうでない場合は、デフォルトブランチで最も最近のスキャン結果と比較されます。

Azure DevOps 環境で Local Scanner を設定するための一般情報については、こちらを参照してください [この記事](/docs/docs-ja/kdosukyan/local-code-scanning/github-action-setup-for-local-code-scanning.md).\
PRゲート付きスキャンの設定例:

```yaml
trigger: none

pr:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

container:
  image: aikidosecurity/local-scanner:latest
  options: --entrypoint=""

steps:
  - checkout: self
    clean: true
    fetchDepth: 0

  - bash: |
      echo "PR対象ブランチ（完全参照）: $SYSTEM_PULLREQUEST_TARGETBRANCH"
      echo "PRソースブランチ（完全参照）: $SYSTEM_PULLREQUEST_SOURCEBRANCH"

      # プレフィックスを削除
      TARGET_BRANCH=${SYSTEM_PULLREQUEST_TARGETBRANCH#refs/heads/}
      echo "プレフィックスを削除したターゲットブランチ: $TARGET_BRANCH"

      # マージベースを計算するためにターゲットブランチを取得
      git fetch origin "$TARGET_BRANCH"

      BASE_COMMIT=$(git merge-base HEAD "origin/$TARGET_BRANCH")
      echo "ベースコミットSHA: $BASE_COMMIT"

      echo "##vso[task.setvariable variable=baseCommitId]$BASE_COMMIT"
    displayName: 'ベースコミットSHAを取得'

  - script: |
      aikido-local-scanner scan $BUILD_SOURCESDIRECTORY \
        --apikey $(AIKIDO_API_KEY) \
        --repositoryname $BUILD_REPOSITORY_NAME \
        --branchname $(System.PullRequest.SourceBranch) \
        --gating-mode pr \\
        --fail-on critical \\
        --base-commit-id $(baseCommitId) \
        --head-commit-id $(System.PullRequest.SourceCommitId)
    displayName: 'Aikido PRスキャンを実行'
```

このパイプラインを main ブランチの Build Validation として追加してください:

1. Project Settings → Repositories → Policies → Branch Policies に移動します
2. main ブランチを選択します
3. Build Validation を追加
4. このパイプラインを選択
5. 次のように設定します:
   * トリガー: 自動


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.aikido.dev/docs/docs-ja/kdosukyan/local-code-scanning/pr-gating/azure-devops-pr-gating-using-local-scanner.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
