Gitlab CI/CD to restore DACPAC to Azure SQL

Hello, I am completely new to gitlab ci/cd. I needed to know how I can add a step to take an existing DACPAC and restore it to Azure SQL. Can anyone provide some guidance here?

Is a DACPAC something like a binary blob or database backup that gets uploaded to Azure SQL somehow? Please share more details how this is performed manually on the CLI for example, and link documentation resources.

It’s basically a fancy zip that has data and schema. To deploy via Azure Pipelines, the yaml looks like:

  • task: SqlAzureDacpacDeployment@1
    displayName: Execute Azure SQL : DacpacTask
    azureSubscription: ‘’
    ServerName: ‘’
    DatabaseName: ‘’
    SqlUsername: ‘’
    SqlPassword: ‘’
    DacpacFile: ‘<Location of Dacpac file in $(Build.SourcesDirectory) after compilation>’

To do this using SqlPackage, you can do this:

SqlPackage.exe /Action:Publish /SourceFile:“” /TargetDatabaseName: /TargetServerName:“”

Assuming that the SqlPackage blob is stored somewhere accessible (Generic package registry, Git LFS object, etc.), and putting the YAML into the Git repository, you should be able call the command in a Windows environment (GitLab Runner). Or the yaml is not needed and you can add all parameters to the SqlPackage call.

  tags: [windows] # needs a GitLab Runner that runs on Windows, use the tag during registering to assign the job 
    # TODO: Download or prepare the SqlPackage first 
    # TODO: Ensure that the yaml task file is in the same repository that will be cloned to the runner job (if needed)
    # Run SqlPackage with all parameters 
    - SqlPackage.exe /Action:Publish /SourceFile:"" /TargetDatabaseName:"mydb" /TargetServerName:“myserver” /SqlUsername:"myuser" /SqlPassword:"mypass"

For SqlUsername and SqlPassword I’d suggest looking into environment variables that store the secret values in the project settings > CI/CD > CI/CD Variables, and not persist them plain text in .gitlab-ci.yml GitLab CI/CD variables | GitLab access should work with %variablename% following the Windows syntax, but I haven’t done this before.

I also found a blog post that describes how to create a container image on Linux that runs sqlpackage, which could also be an option with GitLab. Automatically Deploy your Database with Dacpac Packages using Linux and Azure DevOps | Programming With Wolfgang and this one shedding some light into the CLI parameters: A simple database deploy pipeline using sqlpackage |