Use the VSTS Release extension
Published 10 March 2016
This tutorial takes you through each stage of setting up a database release pipeline using Visual Studio Team Services (VSTS) and the DLM Automation Release extension.
Before you start, you must have already set up a DLM Automation build in VSTS that creates a NuGet package from your source-controlled database and publishes it as an artifact. See Using the VSTS Build extension.
1. Install the DLM Automation Release extension
In VSTS, in the top-right, click the "shopping-bag" icon.
Go to Visual Studio Team Services extensions.
In the Build and Release area, click see more.
Click the Redgate DLM Automation Release item.
Click Install.
Choose the account you want to install to, and click Confirm.
Click Close.
2. Create a release definition
A VSTS release definition is similar to a build definition. It defines your environments, release processes, variables and other options.
- In VSTS, open your project.
In this tutorial, we'll be releasing the database, WidgetShop. This is the same database used in the tutorial Using the VSTS Build extension. - In the top menu, click RELEASE.
- Click the icon to create a new release definition.
- Click Empty. This creates an empty definition. Click OK.
- In the yellow bar, enter a name for your build definition. Click Save.
3. Create the preproduction and production environments
An environment usually represents a stage in your development process. In VSTS, for each environment, you need to set up approval steps, variables, and a set of tasks that define the release process to that environment.
For the WidgetShop database, we'll create two environments: preproduction and production. The production environment is your live hardware and software. The preproduction (or "staging") environment is used for testing and should closely match the production environment.
Although it's not covered in this tutorial, releasing to these environments is also likely to involve releasing a corresponding application or website.
To create the two environments:
- Click Default Environment, and rename this Preproduction.
- Click Add environments.
- Click Empty to start with an empty definition. Click OK.
- Name this environment Production.
4. Link to a build definition
A release definition is often linked to a build definition. The build definition is used to release the artifacts published by a particular build. In this case, we want to release the NuGet package that was published by our WidgetShop build definition.
- Click Link to a build definition.
- In Type, select Build.
- In Project, select WidgetShop.
- In Source, select WidgetShop.
- Click Link.
5. Build the deployment process
There are many ways to set up a deployment process, depending on your requirements.
In this tutorial, we'll use the following method:
- Overwrite the preproduction schema with the production schema
- Create deployment resources
These include the update script that will be applied to production in the final step. - Deploy to preproduction
This uses the same update script that was created in the previous step. - Review and approve
This allows you to examine the deployment resources and the preproduction database before proceeding. - Deploy to production
To set up this process, we'll add three tasks to the preproduction environment and one task to the production environment.
5.1. Add the "Overwrite preproduction with production" task
- In the Preproduction environment, click Add Tasks.
- In the Deploy section, find Redgate DLM Automation Release in the list of tasks and click the Add button to the right of this.
- Click Close.
- Click the icon and rename the task Overwrite preproduction with production.
- In Operation, click Deploy a database to a database.
- In Source SQL Server instance, enter the name of your production server.
- In Source database name, enter the name of your production database.
Select the Authentication Method of the production server.
If you select SQL Server Authentication, you also need to give your SQL Server username and password.
- In the Target database section, enter the following details:
- In Target SQL Server instance, enter the name of your preproduction server.
- In Target database name, enter the name of your preproduction database.
Select the Authentication Method for the production server.
Click Save.
5.2. Add the "Create database release" task
- In the Preproduction environment, click Add Tasks.
- In the Deploy section, find Redgate DLM Automation Release in the list of tasks and click the Add button to the right of this.
- Click Close.
- Click the icon and rename the task Create database release.
- In Operation, select Create a database release.
- In Database package, select the NuGet package you want to deploy. For example:
$(System.DefaultWorkingDirectory)\WidgetShop\WidgetShop\WidgetShop.2.2.205.nupkg - Because the name of this package will change for each build you deploy, you need to replace the build number, which is 205 in the example above, with either $(BUILD.BUILDNUMBER) or $(BUILD.BUILDID) - depending on what you specified in the Build step on the "NuGet package version" section.
- In Export Path, enter the path to where you want to put the deployment resources. It's a good idea to include the release name. For example:
D:\DeploymentResources\$(RELEASE_DEFINITIONNAME)\$(RELEASE_RELEASENAME) - In the Target database section, enter the following details:
- In Target SQL Server instance, enter the name of your production server.
- In Target database name, enter the name of your production database.
- Choose the Authentication Method for the production server.
- Click Save.
5.3. Add the "Deploy to Preproduction" task
- In the Preproduction environment, click Add Tasks.
- In the list of tasks, in the Deploy section, find Redgate DLM Automation Release and click Add next to this.
- Click Close.
- Click the icon and rename the task Deploy to Preproduction.
- In Operation, select Deploy a database release from deployment resources.
- In Deployment Resources Path, enter the same path you entered for the Export Path in the previous task. For example:
D:\DeploymentResources\$(RELEASE_DEFINITIONNAME)\$(RELEASE_RELEASENAME) - In the Target database section, enter the following details:
- In Target SQL Server instance, enter the name of your preproduction server.
- In Target database name, enter the name of your preproduction database name.
- Choose the Authentication Method for the production server.
- Click Save.
5.4. Add the "Deploy to Production" task
- In the Production environment, click Add Tasks.
- In the Deploy section, find Redgate DLM Automation Release in the list of tasks and click the Add button to the right of this.
- Click Close.
- Click the icon and rename the task Deploy to Production.
- In Operation, select Deploy a database release from deployment resources.
- In Deployment Resources Path, enter the same path you entered for the Deployment Resources Path in the previous task. For example:
D:\DeploymentResources\$(RELEASE_DEFINITIONNAME)\$(RELEASE_RELEASENAME) - In Target database section, enter the following details:
- In Target SQL Server instance, enter the name of your production server.
- In Target database name, enter the name of your production database name. For our examples, we've used WidgetProd.
- Choose the Authentication Method for the production server.
- Click Save.
6. Select an agent
In VSTS, you can either use a hosted agent or an on-site agent. Hosted agents are suitable for deploying to Azure. However, they can't deploy to an on-site SQL Server, unless it's accessible to the internet. Hosted agents also make the deployment resources directory inaccessible. Because of this, we recommend you use an on-site agent. Click here for more information about installing and setting up an on-site VSTS agent.
To set the agent used by a release definition:
- Go to your release definition.
- Click the ellipsis next to an environment. For this release, you'll need to do this for both the preproduction and production environments.
- Click Agent options.
- In Default queue, select the queue associated with your agent.
- Click OK.
7. Run a release without a review step
You're now ready to try out the release process.
- Click Release and select Create Release.
- Select the build version you want to release.
- In the Environments section, select the Production environment. This means the release process will deploy to both preproduction and production.
- Click Create.
The release will begin. To watch it progress:
- click ReleaseRelease-XXXhas been queued.
- click Logs.
The release process will normally take about 30 seconds. However, it may take longer the first time you run it because the agent needs to download the DLM Automation Release extension.
If the completion is successful, all the steps will be ticked, as in the example below.
If you see an error, the first diagnostic step is to review the logs. Common causes of error are an incorrect password or a non-existent directory.
8. Add an "Approval" step
At the moment, the release process automatically deploys to production after deploying to preproduction. We want to add an "Approval" step that pauses the process after deploying to preproduction so you can review the Change report in the deployment resources and check the preproduction database.
- Go to the WidgetShop release definition.
- Click Edit.
- Click the ellipsis next to the Preproduction environment.
- Click Assign Approvers.
- In Post-deployment approver, deselect Automated and enter the VSTS user or group who should approve the release.
- Click OK.
- Click Save.
9. Run a full release
You're now ready to run another release, and check the approval step works:
- Click Release and select Create Release.
- Select the build version you want to release.
- In the Environments section, select the Production environment.
- Click Create.
You'll be prompted for approval when the process has released to preproduction. You may receive an email, or see a banner in VSTS reading A post-deployment approval is pending for 'Preproduction' environment. Approve or Reject. - Review the Change report at:
D:\DeploymentResources\$(RELEASE_DEFINITIONNAME)\$(RELEASE_RELEASENAME) \Reports\Changes.html.
This shows:- A list of changes that will be made
- A list of warnings
- The update script (also available in the parent folder, in Update.sql)
- You can also review the preproduction database before deciding whether to continue deploying to production.
- Click Approve or Reject.
- Enter a suitable comment, then click Approve.
The deployment process will now continue and release to production.