Pipelines¶
Every pipeline does the same three things: install Sql2DevOps with your download key, get a clone of the control repository, and run the commands. The secrets you need:
| Secret | Purpose |
|---|---|
SQL2DEVOPS_DOWNLOAD_KEY |
Downloads the tool (get yours) |
SQL2DEVOPS_SIGNING_KEY |
Signs the history (sql2devops key generate) |
SQL2DEVOPS_LICENSE |
Paid edition, when you have one |
| Connection strings | One per environment, named in project.yaml (dsn_env) |
| A Git token | Write access to the control repository |
GitHub Actions¶
jobs:
database:
runs-on: ubuntu-latest
environment: production # optional: GitHub's own approval gate
steps:
- uses: actions/checkout@v4
- name: Install Sql2DevOps
run: curl -fsSL https://sql2devops.com/install.sh | sh
env:
SQL2DEVOPS_DOWNLOAD_KEY: ${{ secrets.SQL2DEVOPS_DOWNLOAD_KEY }}
SQL2DEVOPS_VIA: action
- name: Control repository
run: git clone https://x-access-token:${{ secrets.CONTROL_REPO_TOKEN }}@github.com/your-org/sql-control.git control
- name: Submit and promote
run: |
export PATH="$HOME/.local/bin:$PATH"
sql2devops package submit --auto-version ./db/CHG-1001
sql2devops promote CHG-1001 --project finance
env:
SQL2DEVOPS_CONTROL_DIR: control
SQL2DEVOPS_SIGNING_KEY: ${{ secrets.SQL2DEVOPS_SIGNING_KEY }}
SQL2DEVOPS_LICENSE: ${{ secrets.SQL2DEVOPS_LICENSE }}
FINANCE_DEV_DSN: ${{ secrets.FINANCE_DEV_DSN }}
In GitHub Actions the actor is github:<login> automatically, and approve --automatic uses the run URL as evidence when --evidence is not given.
GitLab CI¶
database:
image: alpine:3.20
before_script:
- apk add --no-cache curl git
- curl -fsSL https://sql2devops.com/install.sh | sh
- export PATH="$HOME/.local/bin:$PATH"
- git clone "https://oauth2:${CONTROL_REPO_TOKEN}@gitlab.com/your-group/sql-control.git" control
script:
- sql2devops package submit --auto-version ./db/CHG-1001
- sql2devops promote CHG-1001 --project finance
variables:
SQL2DEVOPS_CONTROL_DIR: control
Define SQL2DEVOPS_DOWNLOAD_KEY, SQL2DEVOPS_SIGNING_KEY, the connection strings and CONTROL_REPO_TOKEN as masked CI/CD variables.
Azure DevOps¶
steps:
- pwsh: |
$env:SQL2DEVOPS_DOWNLOAD_KEY = "$(SQL2DEVOPS_DOWNLOAD_KEY)"
irm https://sql2devops.com/install.ps1 | iex
displayName: Install Sql2DevOps
- pwsh: |
git clone https://$(CONTROL_REPO_TOKEN)@dev.azure.com/your-org/your-project/_git/sql-control control
sql2devops package submit --auto-version ./db/CHG-1001
sql2devops promote CHG-1001 --project finance
env:
SQL2DEVOPS_CONTROL_DIR: control
SQL2DEVOPS_SIGNING_KEY: $(SQL2DEVOPS_SIGNING_KEY)
FINANCE_DEV_DSN: $(FINANCE_DEV_DSN)
On Linux agents use the install.sh line from the GitHub example.
Jenkins¶
pipeline {
agent any
environment {
SQL2DEVOPS_DOWNLOAD_KEY = credentials('sql2devops-download-key')
SQL2DEVOPS_SIGNING_KEY = credentials('sql2devops-signing-key')
FINANCE_DEV_DSN = credentials('finance-dev-dsn')
SQL2DEVOPS_CONTROL_DIR = 'control'
}
stages {
stage('Database') {
steps {
sh 'curl -fsSL https://sql2devops.com/install.sh | sh'
sh 'git clone [email protected]:your-org/sql-control.git control'
sh '$HOME/.local/bin/sql2devops package submit --auto-version ./db/CHG-1001'
sh '$HOME/.local/bin/sql2devops promote CHG-1001 --project finance'
}
}
}
}
Validating in CI¶
Before merging, run the package against a throwaway database, without touching the control repository:
sql2devops package run -d postgres ./db/CHG-1001