# How can I use the Vercel CLI for custom workflows?

**Author:** Lee Robinson

---

You can use the Vercel CLI with any CI/CD provider such as [Azure DevOps](https://azure.microsoft.com/en-us/services/devops/) to generate Preview Deployments for every `git` push and deploy to Production when code is merged into the `main` branch.

This approach is useful for developers seeking full control over their CI/CD pipeline, those unable to use Vercel's [Git integration](https://vercel.com/docs/deployments/git) or those with a [trunk-based development](https://trunkbaseddevelopment.com/) workflow.

## Building Your Application

You can build your application locally (or in a pipeline) without giving Vercel access to the source code through `vercel build`. Vercel automatically detects your frontend framework and generates a `.vercel/output` folder conforming to the [Build Output API specification](https://vercel.com/docs/build-output-api/v3).

`vercel build` allows you to build your project within your own CI setup and upload _only_ those build artifacts (and not the source code) to Vercel to create a deployment.

## Deploying Your Application

There are 3 options for deploying your application:

1\. `git push`: Uploads all local branch commits to the corresponding remote branch

2\. `vercel deploy`: Build a project locally or in your own CI environment

3\. `vercel deploy --prebuilt`: Deploy a build output directly to Vercel, bypassing the Vercel build system

## Creating a Custom Workflow

1. Retrieve your [Vercel Access Token](https://vercel.com/guides/how-do-i-use-a-vercel-api-access-token)
   
2. Install the [Vercel CLI](https://vercel.com/cli) and run `vercel login`
   
3. Inside your folder, run `vercel link` to create a new Vercel project
   
4. Inside the generated `.vercel` folder, save the `projectId` and `orgId` from the `project.json`
   
5. Add `VERCEL_TOKEN`, `VERCEL_ORG_ID`, and `VERCEL_PROJECT_ID` as environment variables in your CI/CD provider
   
6. Then set your custom workflow. For example, to build your application locally you could use:
   

`npm install --global vercel vercel pull --yes --environment=preview --token=YOUR_VERCEL_TOKEN vercel build --token=YOUR_VERCEL_TOKEN vercel deploy --prebuilt --token=YOUR_VERCEL_TOKEN`

You can also take full control over your application, deciding [when to assign domains](https://vercel.com/docs/deployments/promoting-a-deployment#staging-and-promoting-a-production-deployment). This allows you to run tests or wait for other elements to be ready before assigning production domains to your new deployment.

## Examples of Custom Workflows

The following examples show how to use the Vercel CLI as shown above:

- [GitHub Actions](https://github.com/vercel/examples/tree/main/ci-cd/github-actions)
  
- [Bitbucket Pipelines](https://github.com/vercel/examples/tree/main/ci-cd/bitbucket-pipelines)

---

[View full KB sitemap](/kb/sitemap.md)
