Big Picture: We are using Azure DevOps release process (so far we create steps in designer, not YAML pipelines). We release to 3 environments with 3 different databases. Part of the release is deploy database from DACPAC file. Since using SqlPackage.exe to publish directly to database is not very transparent (you don't see and review the actual SQL script), we wanted to do release in 2 stages:
- Create SQL script from DACPAC and review it
- After approval run app and db deploy from previously generated script.
Issue: How to share sql script file between stages and how to see it for approval. Stages can be triggered on different agent.
What I've tried:
- Publishing script as build artifact - this won't work cause to generate script I need to connect to database and connecting to it should not be part of build process, especially connecting to production database.
- Publish artifact to Azure Pipelines as release step - it's not allowed on release, only for builds Publish
- Publish artifact to file share - I'm not sure how this exactly work, documentation is not very well done. Moreover regular windows file sharing would be difficult to set in our infrastructure, I would rather avoid it.
Any other suggestions?
Azure DevOps now allows to download files that have been published as artifacts in earlier stages of the pipeline.
In the code I am sharing, I have implemented SQL schema generation with database changes, followed by publishing those changes (after approval). Some remarks:
sqlpackage
is only correct when Visual Studio 2019 is installed, like inwindows-2019
images.targetDBConnectionString
servername
databasename
adminlogin
adminPassword
ApplyChanges
stage (within Pipelines menu, choose environments, then theApplyChanges
environment, and thenapprovals and checks
from the three dots button, on the top right corner). This way the changes are not applied to the database before manual approval takes place.