> 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/pr-and-release-gating/azure-pr-gating/azure-pipelines-setting-up-gating-for-pull-requests-via-code.md).

# Azure DevOps: Setting Up Gating for Pull Requests via Code

### Important Notice

{% hint style="danger" %}
We do not recommend using this functionality anymore, but use the PR gating via the Aikido Dashboard instead as it does not use CI minutes, easier management in bulk and less error-prone.
{% endhint %}

### Intro

Aikido's integration with Azure Pipelines allows you to flag or block risky code from being merged. Our CI scans target **IaC**, **SAST**, and **dependency issues**.

If you're on the Aikido Pro plan, you can also use this integration for [CI Gating](https://help.aikido.dev/en/articles/7945775-setting-up-feature-branch-scanning).

> Note: this integration is not available for TFVC repos.

## Set up integration <a href="#set-up-integration" id="set-up-integration"></a>

**Step 1.** Go to our [CI Integrations page](https://app.aikido.dev/settings/integrations/continuous-integration).

**Step 2.** Generate an authentication token. You will need to expose this in your CI environment for the integration. Make sure to copy the token in this step.

**Step 3.** Click on Azure Pipelines. You will be redirected to the Aikido Azure Extension Page

![Integrate CI tools to block risky code merges: GitHub, GitLab, Bitbucket, Azure.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-0bc70b698c67da7b7078756ca3cf516c60b6d2bc%2Fucarecdn-8787fd95-f430-4ceb-9a6a-2e9c085d81fe.png?alt=media)

## Install the extension <a href="#install-the-extension" id="install-the-extension"></a>

Click the green "Get it free"-button

![Aikido Security Scanner: Free Azure Pipelines integration tool for security scanning.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-0c0eaae03f2a7360bede021414c17d09691fea9d%2Fucarecdn-e1fd7298-e234-4057-8943-57499e60f98d.png?alt=media)

Select the organisation where you want to install the extension and click install

![Select an Azure DevOps organization to install a private extension.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-ef7687adc6aa01b2ca6d98d78d837873846c9c44%2Fucarecdn-6efd326d-b1e8-418e-a951-b29c06ca06c1.png?alt=media)

The extension is now installed. You can verify this by going to "Organisation Settings > Extensions" In your Azure Organisation

![Aikido Security Scanner extension installed in Azure DevOps organization settings.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-2e08f715948fd22980c7a252f13d4470a656de19%2Fucarecdn-d2df10f4-1aa6-4e57-8f3c-687214412530.png?alt=media)

## Set up the pipeline for PRs <a href="#set-up-the-pipeline-for-prs" id="set-up-the-pipeline-for-prs"></a>

We recommend creating a separate Pipeline for this, but it can be integrated in existing build

Go to Pipelines and create a new azure pipeline. At the configure step select "Starter pipeline"

![Pipeline configuration options for various Node.js project templates and deployment choices.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-38acccc893daaa10eb940d381c0be5e80e292b44%2Fucarecdn-cd05ea44-e92e-485a-b9f8-6923a4e03341.png?alt=media)

In the yml-file use following content.

```
pool:
  vmImage: ubuntu-latest
steps:
  - task: AikidoScanTask@1 
    inputs: 
      secretKey: $(AIKIDO_SECRET) 
      minimumSeverity: 'LOW'
      failOnDependencyScan: true
      failOnSastScan: false
      failOnIacScan: false
      failOnTimeout: true
      timeoutSeconds: 180
```

For the secretKey we recommend using a variable to avoid the secretKey from being exposed.

Add a new variable for the AIKIDO\_SECRET. This is the token that you generated earlier in the Aikido app.

Click the Variables button.

![Pipeline YAML review screen with options to edit variables and "Save and run."](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-b840d6a9adb39c5fd748acf4b22dd4876d20be9d%2Fucarecdn-d440d9d8-440a-4e85-9aab-86e8da0dbfd7.png?alt=media)

Click the button with the Plus icon.

![Variables panel with search bar and button to add a new variable.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-556577027d56752832879c8a561c5b2e7edb936e%2Fucarecdn-f9adf410-9c08-4a7b-8638-76c4c89faf69.png?alt=media)

Give your Variable the name "AIKIDO\_SECRET". The value should be the token that you generated earlier in the Aikido app. Check the "Keep this value secret option" to fully secure this secret. Click "OK" to save the variable.

![Configuring a secret environment variable in a CI/CD pipeline settings dialog.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-59492ce048ea2867f7e8f85660cc7d96b4f5a768%2Fucarecdn-6a107e4a-5cb0-478f-92a6-dc995520276c.png?alt=media)

Under the input section there are some required field.

* **secretKey:** This is the token generated in **step2** of [Set up integration](https://help.aikido.dev/en/articles/9099968-setting-up-gating-for-pull-requests-with-azure-pipelines#h_1a95ad3e70). We recommend saving this in an ENV Variable for your pipeline.
* **minimumSeverity:** When issues of this severity are found the pipeline should fail. Possible options are "LOW", "MEDIUM", "HIGH" & "CRITICAL"

Some optional fields are:

* **failOnDependencyScan:** Boolean value that determines whether the scan should fail on the dependency scan. Default is false
* **failOnSastScan:** Boolean value that determines whether the scan should fail on the SAST scan. Default is false
* **failOnIacScan:** Boolean value that determines whether the scan should fail on the IaC scan. Default is false
* **timeoutSeconds:** Integer value that determines when the task should stop running: Default is 180
* **failOnTimeout:** Boolean value that determines whether the scan should fail on timeout. Default is false

Save and Run the pipeline.

Once your pipeline appears in Azure Pipelines. Go to "Branches" And Select "Branch policies" for the target branches of your PRs where you want run the scan.

![Branch overview interface with branch selection, policy, and security options visible.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-8a1563cf258b07ec2dc4e3206edbeb13c6c8193a%2Fucarecdn-25e06f66-3bf0-4cfa-a2bd-890e9a864940.png?alt=media)

Go to Build Validation and click the add icon

![Build validation settings panel with no policies, prompting to add a new one.](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-887b8221b12bd78dd176c6b72477d1fe441b9eaf%2Fucarecdn-58ab5e0c-f40e-4906-bea5-f68cb4824a3b.png?alt=media)

Select your new Aikido Scan pipeline. Fill in your preferred options and make sure to give this build policy a display name.

![Setting up an automatic required build policy for the aikidoDev pipeline named "Aikido Scan."](https://3149773201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyKbzcQGrx7UtrG0nPZZ7%2Fuploads%2Fgit-blob-fb584ec8caaf715985f98575ac8b72c0631bf164%2Fucarecdn-353f1374-3eaf-4b95-8561-c004feabb423.png?alt=media)

Aikido will now scan new PRs where the target branch is this branch. You can set this up for multiple branches

***


---

# 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/pr-and-release-gating/azure-pr-gating/azure-pipelines-setting-up-gating-for-pull-requests-via-code.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.
