--- title_tag: "Using Azure DevOps | CI/CD" meta_desc: This page details how to use Azure DevOps to manage deploying stacks based on commits to specific Git branches, and based on the build reason. title: Azure DevOps h1: Pulumi CI/CD & Azure DevOps meta_image: /images/docs/meta-images/docs-meta.png menu: usingpulumi: parent: cont_delivery weight: 1 aliases: - /docs/reference/cd-azure-devops/ - /docs/console/continuous-delivery/azure-devops/ - /docs/guides/continuous-delivery/azure-devops/ - /docs/guides/continuous-delivery/cd-azure-devops/ - /docs/using-pulumi/continuous-delivery/cd-azure-devops/ --- This page details how to use [Azure DevOps](https://azure.microsoft.com/en-us/services/devops/) to manage deploying stacks based on commits to specific Git branches, and based on the build reason. You may also choose to introduce a [Manual Intervention](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/manual-intervention?view=vsts) task to control the preview vs. update step for any Pulumi stack. Pulumi doesn't require any particular arrangement of stacks or workflow to work in a continuous integration / continuous deployment system. So the steps described here can be altered to fit into any existing type of deployment setup. This page shows you how to use the Pulumi Azure DevOps task extension and the YAML method to configure your DevOps pipeline, but you can easily adapt the steps outlined in the sample YAML file below to the Visual Designer as well. ## Prerequisites - An account on [https://app.pulumi.com](https://app.pulumi.com). - The latest CLI. - [Installation instructions](/docs/install/). - A git repo with your Azure DevOps project set as the remote URL. - To learn more about how to [create a git repo in your DevOps project](https://docs.microsoft.com/en-us/azure/devops/organizations/projects/create-project?view=vsts&tabs=new-nav). - Optional, but recommended, the [Pulumi Azure DevOps task extension](https://marketplace.visualstudio.com/items?itemName=pulumi.build-and-release-task). - Optional for VSCode users, configure intellisense for the task extension as per [Task Extension Intellisense](https://github.com/microsoft/azure-pipelines-vscode#specific-schema) ## Pulumi Task Extension for Azure Pipelines {#pulumi-task-extension} Pulumi provides a task extension that lets you easily use Pulumi in your CI/CD pipelines. It can be used with the Azure Pipelines wizard UI or the YAML config. The task handles installing the Pulumi CLI and running any commands without the need for any scripts. > Pulumi Task Extension for Azure Pipelines can be used with [any cloud provider](#other-clouds) that Pulumi supports. You are not limited to using it only with Azure. ### Command Summary Details regarding parameters and options supported by the extension can be found in the [Pulumi CLI](/docs/cli/) documentation. | Parameter Name | Required? | Parameter Description | |----|---|----| | stack | Yes | Name of stack being managed. Can be of the form `ORG/STACK` or `ORG/PROJECT/STACK`. | | azureSubscription | No | Optionally reference a service connection. If not used, environment variables can be configured with the credentials needed for the applicable Pulumi providers. | | command | No | The applicable `pulumi` cli command (e.g. `preview`, `up`, `destroy`) | | args | No | Option flags (e.g. `--yes`) that can be passed to the given `pulumi` command. Use space to separate multiple args. | | cwd | No | The working directory to run the Pulumi commands. Use this if your Pulumi app is in a different directory. | | versionSpec | No | The Pulumi version that should be used. Defaults to the latest version. If you require a specific version then the format is `1.5.0` or if you just need the latest version then `latest` can be used. | | createStack | No | Set to `true` if the stack should be created if it does not already exist. Defaults to `false`. | | createPrComment | No | Set to `true` to add a comment to your Pull Request (PR). Can only be used in pipelines driven by PRs. Defaults to `false`. See [Log Pulumi Output as PR Comments](#log-pulumi-output-as-pr-comments). | useThreadedPrComments | No | Defaults to `true` to always add a comment to the previously-created comments thread. Set to `false` to have each comment added separately. ### Using the Pulumi Task Extension Install the Pulumi task from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=pulumi.build-and-release-task) to your Azure DevOps organization. The task requires the use of a service connection, which allows the pipeline to connect to your Azure Subscription. The task also looks for the build variable `pulumi.access.token`, and automatically maps it to the environment variable `PULUMI_ACCESS_TOKEN`, that is used by the CLI for non-interactive logins. You may still use the `env` directive to map any other environment variables you wish to make available to your Pulumi app. You can obtain a [Pulumi access token](/docs/pulumi-cloud/accounts#access-tokens) from the Pulumi Cloud. Then use the task in your pipeline yaml. ```yaml # Lines omitted for brevity. ... ... - task: Pulumi@1 condition: or(eq(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.Reason'], 'Manual')) inputs: azureSubscription: "My Service Connection" command: "preview" cwd: "infra/" stack: "acmeCorp/acmeProject/acme-ui" ... ... ``` ### Log Pulumi Output as PR Comments {#log-pulumi-output-as-pr-comments} > This feature is only supported for builds triggered by pull requests created in git repositories hosted by Azure DevOps. Repositories hosted by external VCS such as Bitbucket, GitHub, GitLab are not supported at this time. The Pulumi task supports adding PR comments containing the log output from the Pulumi command that was executed in your build pipeline. Your project's build service user will need additional permissions to perform that action. Follow these steps to grant the build service user the `Contribute to pull requests` permission: - Navigate to the **Project Settings** page and select **Repositories** under the **Repos** heading. - Select the repository where you will be using this feature and then select the **Security** tab. - Now under the **Users** section find the build service user. If you are using the default build service user, the naming convention is ` Build Service` where `` is your project's name. - Change the value of `Contribute to pull requests` to `Allow`. ### Using The Pulumi Task Extension With Other Clouds {#other-clouds} To use the Pulumi Task Extension for Azure Pipelines with other clouds, you can specify the necessary environment variables as build variables or link variable groups to your build and release pipelines. For example, if you are using the [AWS provider](/registry/packages/aws/), you can set the [environment variables](/registry/packages/aws/installation-configuration/) `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. ## Using Pulumi in Azure DevOps Pipelines More details on how to use Pulumi - with or without the [Task Extension](#pulumi-task-extension) - are provided below. ### Stack and Branch Mappings > The names used below are purely for demonstration purposes only. You may choose a naming convention that best suits your organization. The scripts below act on a hypothetical stack: `acmeCorp/acmeProject/acme-ui`. `acme-ui` contains the infrastructure code or `pulumi` program. It also contains an Angular-based SPA. The git repo for this look like this: ``` acme-ui src/ app/ components/ index.html infra/ index.ts Pulumi.yaml Pulumi.acme-ui.yaml azure-pipelines.yml ``` Once you login into the `pulumi` CLI on your machine, you can create a stack by running `pulumi stack init`. To create a `pulumi` program using one of the many available templates, you may run `pulumi new