Once the Vercel extension is set up, your Azure DevOps project is connected to your Vercel Project. You can then use your Azure Pipeline(s) inside your Azure DevOps project to trigger a Vercel Deployment.
This page will help you use the extension in your own use case. You can:
Follow the quickstart to set up the extension and trigger a production deployment based on commits to the main branch
At the end of this quickstart, your Azure DevOps Pipeline will trigger a Vercel production deployment whenever you commit a change to the main branch of your code. To get this done, we will follow these steps:
Create a Vercel Personal Access Token
Create secret variables
Set up the Vercel Deployment Extension from the Visual Studio marketplace
Set up a basic Azure Pipeline to trigger production deployments on Vercel
Test your workflow
Once you have the Vercel Deployment extension set up, you only need to modify your Azure DevOps Pipeline (Steps 4 and 5) to change the deployment workflow to fit your use case.
For security purposes, you should use the above created token in your Azure Pipeline through secret variables.
For this quickstart, we will create the secret variables when we create the pipeline. Once created, these variables will always be accessible to that pipeline
Otherwise, you can create them before you create the pipeline in a variable group or a key vault as long as you make sure that your Azure Project has the right access
This step assumes that your code exists as a repository in your Azure Project's Repos and that your Vercel Project is named azure-devops-extension.
Azure DevOps Pipeline creation at the review stage to create variables and save/edit your pipeline
From your Azure DevOps Project, select Pipelines from the left side bar
Select the New Pipeline button
Select where your code is located (In this example, we uploaded the code as an Azure Repos Git. Select Azure Repos Git and then select your uploaded repository)
Select Node.js for the pipeline configuration
In the Review your pipeline YAML step, select Variables on the top right
Select New Variable, use VERCEL_TOKEN as the name and the value of the Vercel Personal Access Token you created earlier. Check the secret option. Select Ok
Close the Variables window and paste the following code to replace the code in azure-pipelines.yml that you can rename to vercel-pipeline.yml
vercel-pipeline.yml
trigger:- mainpool: vmImage: ubuntu-lateststeps:- task: vercel-deployment-task@1 inputs: vercelProjectId: 'prj_mtYj0MP83muZkYDs2DIDfasdas' //Example Vercel Project ID vercelOrgId: '3Gcd2ASTsPxwxTsYBwJTB11p' //Example Vercel Personal Account ID vercelToken: $(VERCEL_TOKEN) production: true
Make a change in your code inside Azure Repos from the main branch and commit the change
This should trigger another deployment in your Vercel Project
Your Azure DevOps project is now connected to your Vercel project with automatic production deployments on the main branch. You can update or create pipelines in the Azure DevOps project to customize the Vercel deployment behavior by using the options of the Vercel Deployment Extension.
Azure Build Validation under Branch Policies of Project settings
Go to your Azure DevOps Project's page
Select Project settings in the lower left corner
From the Project settings left side bar, select Repositories under Repos
Select the repository where your vercel pipeline is set up
Select the Policies tab on the right side
Scroll down to Branch Policies, and select the main branch
Scroll down to Build Validation and select on the + button to create a new validation policy
Select the pipeline you created earlier and keep the policy marked as Required so that commits directly to main are prevented
Select Save
Create a pull request to the main branch. This will trigger the pipeline, run the deployment and comment back on the pull request with the deployment URL.
From your Azure DevOps Project, select Pipelines from the left side bar
Select the pipeline that you want to edit by selecting the icon
Select the Variables button and add a new secret variable called AZURE_TOKEN with the value of the Azure DevOps Personal Access Token you created earlier. Select Ok
Close the Variables window and paste the following code to replace the code in vercel-pipelines.yml
The vercel-deployment-task creates an output
variable
called deploymentTaskMessage. By setting the name: of the step to
'Deploy', you can access it using $(Deploy.deploymentTaskMessage) which
you can then assign to the input option deploymentTaskMessage of the
vercel-azdo-pr-comment-task task step.
The ID of your Vercel Project. It can alternatively be set as the environment variable VERCEL_PROJECT_ID
vercelOrgId
No
string
The ID of your Vercel Org. It can alternatively be set as the environment variable VERCEL_ORG_ID
vercelToken
No
string
A Vercel personal access token with deploy permissions for your Vercel Project. It can alternatively be set as the environment variable VERCEL_TOKEN
vercelCWD
No
string
The working directory where the Vercel deployment task will run. When omitted, the task will run in the current directory (default value is System.DefaultWorkingDirectory). It can alternatively be set as the environment variable VERCEL_CWD
production
No
boolean
Boolean value specifying if the task should create a production deployment. When omitted or set to false, the task will create preview deployments
debug
No
boolean
Boolean value that enables the --debug option for the internal Vercel CLI operations