> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bytebase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Database GitOps with Azure DevOps Pipeline

This is part of our database GitOps series with Bytebase:

* [Database GitOps with GitHub Actions](/tutorials/gitops-github-workflow)
* Database GitOps with Azure DevOps Pipeline (this one)
* [Database GitOps with GitLab CI](/tutorials/gitops-gitlab-workflow)
* [Database GitOps with Bitbucket Pipelines](/tutorials/gitops-bitbucket-workflow)

***

This tutorial shows you how to build a database GitOps workflow using Azure DevOps Pipeline and Bytebase API. You'll learn to create a streamlined database release workflow where you can:

* Submit SQL migrations through Azure DevOps
* Automatically run SQL reviews on pull requests
* Auto-create and deploy Bytebase releases when merging to `main`

While we use Azure DevOps Pipeline in this guide, you can apply these concepts to other CI platforms like [GitHub Actions](/tutorials/gitops-github-workflow), GitLab CI, or Bitbucket Pipelines using the Bytebase API.

This tutorial code repository is at [https://dev.azure.com/bytebase-hq/\_git/bytebase-example](https://dev.azure.com/bytebase-hq/_git/bytebase-example)

## Prerequisites

* A Bytebase instance (Bytebase Cloud or self-hosted)
* For self-hosted version, you need [Docker](https://www.docker.com/) to run Bytebase

## Automatic Rollout across environments

### Step 1 - Set up Bytebase

<Tabs>
  <Tab title="Cloud">
    Use [Bytebase Cloud](https://cloud.bytebase.com/) for instant setup without infrastructure management. CI/CD services can connect immediately.

    **Best for:** Quick testing, evaluation, and small teams
  </Tab>

  <Tab title="Self-Hosted">
    Run Bytebase in Docker within your infrastructure:

    ```bash theme={null}
    docker run --rm --init \
      --name bytebase \
      --publish 8080:8080 --pull always \
      --volume ~/.bytebase/data:/var/opt/bytebase \
      bytebase/bytebase:latest
    ```

    **Network Access Options:**

    * **For testing:** Use tools such as [ngrok](https://ngrok.com/) or [VS Code port forwarding](https://code.visualstudio.com/docs/editor/port-forwarding) to temporarily expose your local Bytebase to cloud CI/CD services. After exposing, configure the **External URL** in Bytebase **Settings > General**.

    * **For production:** Use self-hosted CI/CD runners within your private network. Never expose production Bytebase to the internet.

    **Best for:** Organizations with security requirements or existing infrastructure
  </Tab>
</Tabs>

See [Network Architecture guide](/get-started/self-host/network-architecture#2-self-hosted-bytebase-production).

### Step 2 - Create Service Account

1. Log in as `Workspace Admin`, and go to **IAM & Admin** > **Users & Groups**. Click **+ Add User**, fill in with `api-sample`, and assign the `Workspace Member` and `GitOps Service Agent` roles, which are sufficient for this tutorial, then click **Confirm**.

2. Find the newly created service account and **Copy Service Key**. We will use this token to authenticate the API calls.
   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/share/service-account-key.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=8817df098a420e992c8c1be0ce2196ac" alt="service-account-key" width="1354" height="218" data-path="content/docs/tutorials/share/service-account-key.webp" />

### Step 3 - Configure SQL Review in Bytebase

Since you will need to run SQL review on your PRs, you need to configure the SQL review in Bytebase.

1. Go to **CI/CD** > **SQL Review**, click **Create SQL Review**.

2. Select the `Sample Template` and click **Next**.
   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/share/bb-sql-review-sample.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=cb1d7fce1fe86e6c4953e35d3bd20978" alt="bb-sql-review-sample" width="2144" height="1218" data-path="content/docs/tutorials/share/bb-sql-review-sample.webp" />

3. Select `Prod` environment as the attached resources and click **Confirm**. Now the SQL review is enabled for the `Prod` environment.
   <img src="https://mintcdn.com/dbx/vw8BbfZhlW9y-cr_/content/docs/tutorials/share/bb-sql-review-prod.webp?fit=max&auto=format&n=vw8BbfZhlW9y-cr_&q=85&s=74081ee5e1cf277cb659e7f1cddab8bd" alt="bb-sql-review-prod" width="2136" height="1224" data-path="content/docs/tutorials/share/bb-sql-review-prod.webp" />

### Step 4 - Copy from the Example Repository and Configure Variables

1. Create a new project. Copy `pipelines` folder from [https://dev.azure.com/bytebase-hq/\_git/bytebase-example](https://dev.azure.com/bytebase-hq/_git/bytebase-example). There are two workflows in this repository:

   * `pipelines/sql-review.yml`: [Lint the SQL](/sql-review/review-policy/) migration files after the PR is created.
   * `pipelines/rollout-release.yml`: Create a release in Bytebase after the PR is merged to the `main` branch.

2. Go into `pipelines/sql-review.yml` and `pipelines/rollout-release.yml`. In the `env` section, replace the variable values with your own and commit the changes.

   * **BYTEBASE\_URL**: Your Bytebase instance URL (e.g., `https://bytebase.your-company.com` or your Bytebase Cloud URL)
   * **BYTEBASE\_SERVICE\_ACCOUNT**: `api-example@service.bytebase.com` (the service account you created in the previous step)
   * **BYTEBASE\_PROJECT**: `projects/project-sample` (the sample project in the Bytebase)
   * **BYTEBASE\_TARGETS**: `instances/test-sample-instance/databases/hr_test,instances/prod-sample-instance/databases/hr_prod` (the two default databases in the sample project)
   * **FILE\_PATTERN**: `migrations/*.sql` (the pattern of the migration files)

   <Note>
     The pipelines run `bytebase-action check` and `bytebase-action rollout`, which verify
     version compatibility before executing. For Bytebase Cloud, use
     `bytebase/bytebase-action:cloud`; for self-hosted Bytebase, use the image tag matching
     your Bytebase server version, for example `bytebase/bytebase-action:3.14.0`.
   </Note>

3. Go to branch policy for `main` branch, add `check-release` as a required check. You don't need to add `rollout-release` as a required check because it will be triggered automatically when the PR is merged.

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-branch-policy.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=6c085efa65e9fcdc7ae2694a17dfe968" alt="ad-branch-policy" width="2634" height="1456" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-branch-policy.webp" />

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-policy-build.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=26b4682dcdf830cc2558531151577bb2" alt="ad-policy-build" width="2638" height="1458" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-policy-build.webp" />

*In `pipelines/rollout-release.yml`, pay attention to `BYTEBASE_TARGETS` in `deploy-to-test` stage. You should put all the databases including both `Test` and `Prod` environments. NOT ONLY the `Test` database.*

### Step 5 - Create the migration files

To create migration files to trigger release creation, the files have to match the following pattern:

* A migration file should start with digits, which is also its version. e.g. `202503131500_create_table_t1_ddl.sql`.
* A migration file may end with 'ddl' or 'dml' to indicate its change type. If it doesn't end with any of the two, its change type is DDL by default.

1. Within your forked repository, create the following migration files under `migrations` directory:

   * 202503131500\_create\_table\_t1\_ddl.sql

   ```sql theme={null}
   CREATE TABLE t1 (
    id SERIAL PRIMARY KEY,
    name TEXT
   );
   ```

2. Commit to a new branch and create a pull request, the `check-release` workflow will be triggered. There will be a warning in the SQL review result.

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-check-pass.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=3aa13c2677175eccabbb2d687588600b" alt="ad-check-pass" width="2572" height="1440" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-check-pass.webp" />

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-check-warning.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=c76cfd2864be384ae2c522ec8018dc33" alt="ad-check-warning" width="2632" height="1454" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-check-warning.webp" />

3. According to the SQL review result, you can do some changes to the SQL files and push to the branch. Then you should see the SQL review has passed. There are no warnings in the SQL review result.

   ```sql theme={null}
    CREATE TABLE t1 (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL
   );
   ```

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-check-no-warning.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=d280fb5bdda7c00a695d9cfab7351c71" alt="ad-check-no-warning" width="2568" height="1434" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-check-no-warning.webp" />

4. When the SQL review is passed, you can merge the pull request. The `rollout-release` workflow will be triggered to create a **release** in Bytebase and then deploy automatically.

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=af462cae103021cae7da0f2edc897ce2" alt="ad-rollout" width="2754" height="1744" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout.webp" />

5. You need to permit the release to be deployed to the production environment the first time.

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout-permit.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=06c2b50c52849e1f759791e2c7d3892e" alt="ad-rollout-permit" width="2744" height="1742" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout-permit.webp" />

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout-prod.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=8c4d8cd8a04bac6d40c48bfeebcae8cc" alt="ad-rollout-prod" width="2754" height="1742" data-path="content/docs/tutorials/gitops-azure-devops-workflow/ad-rollout-prod.webp" />

6. If you click the test stage and expand the different sections, you can follow the links to Bytebase.

   <img src="https://mintcdn.com/dbx/QHI-wM3-9mvQwL51/content/docs/tutorials/gitops-azure-devops-workflow/bb-rollout-preview.webp?fit=max&auto=format&n=QHI-wM3-9mvQwL51&q=85&s=f90c4ad2b490dcdf8d81537dc2bcf8b3" alt="bb-rollout-preview" width="2292" height="1340" data-path="content/docs/tutorials/gitops-azure-devops-workflow/bb-rollout-preview.webp" />

7. You may customize the workflow file to trigger deployment manually according to your needs.

## Summary

Now you have learned how to database GitOps with Azure DevOps Pipeline. If you want to trigger a release creation with other git providers (e.g. GitLab, Bitbucket, [GitHub Actions](/tutorials/gitops-github-workflow)), you may customize the workflow file.
