In this lab, we will create a manual release process with Migration-Based development and we will begin releasing our changes to downstream databases.

DevOps MPP Course Source

Prerequisites:

Lab Tasks:

In this lab, we will begin releasing our changes to downstream databases.

  • Prepare your local environment_
  • Implement a Continuous Release process for Integration
  • Implement a Release process for QA

Estimated Lab Time:

  • approx. 40 minutes

Task 1: Prepare our local environment

We will set up a local environment for releases.

  1. Open SQL Server Management Studio and connect to your instance. Enter this code in a query window and execute it. This will create the empty databases that we will use for our release process.

     CREATE DATABASE WWI_QA;
     GO
     CREATE DATABASE WWI_Staging;
     GO
    
  2. Verify that the databases exist. You should see the WWI_QA and WWI_Staging databases if you refresh the database folder.

    In Object Explorer, in the Databases folder, WWI_QA and WWI_Staging display.

  3. Expand the Security folder, right-click Logins, then click New Login.

    The Security folder is expanded, the Logins folder is selected, and from its right-click menu, New Login in selected.

  4. Configure a new login for your builds with a strong password. This is an account the agent will use, so choose SQL Server Authentication. If your agent runs as a service with a specific account, you can add that here. The name we are using in the lab is VSTSRelease. Uncheck Enforce Password Policy, then click OK.

    In the New Login dialog box, fields are set to the previously defined settings.

  5. On the User Mapping page, we will add the login to the databases for integration and QA. We will use the db_owner role as the user must be able to control all aspects of the database.

    The Login Properties page has three panes. In the first pane, under Select a page, User Mappings is selected. In the second pane, in the Users mapped to this login table, the check box for WWI_Integration is selected. In the third pane, under Database role membership for WWI_Integration, the check boxes for db owner and db securityadmin are selected.

    Remember this user and password. We will use it in the sections below.

  6. Repeat the previous steps for a new login called VSTSReleaseStaging, mapping this user to only the WWI_Staging database as db_owner.

Task 2: Implement a Continuous Release process for Integration

We will implement an automation release process for continuous integration output.

  1. Open your VSTS account, select the WideWorldImporters-RR project, click the Build&Release menu at the top and select Releases. You should see an empty release definition page.

    On the WideWorldImporters-RR page, the Build&Release menu is selected, and the Releases tab is selected. Under Release, the New definition button is selected.

  2. Click New definition button. You will receive a list of templates to select. We will choose the Empty definition, then click Next.

    On the Create release definition page, under Select a template, Empty is selected.

  3. The next page asks which project and build source to use. The default project and your CI definition should be listed. Check the Continuous Deployment check box and click the Create button.

    On the Create release definition page, under Choose a source that publishes the artifact to be deployed, Build is selected. The Project and the Source (Build definition) fields are set to WideWorldImporters-RR. At the bottom is a check box for Continuous deployment.

  4. This will create an empty release definition with a default name.

    On the Releases tab, in the left pane, under Release Definitions, All release definitions is selected. On the right, in the Definition*.New Empty Definition pane, under Add environment, Environment 1 is selected.

    Click the pencil icon next to the name to edit it. Enter Release to Integration as the name.

    The Definition field now displays Release to Integration.

  5. Let us start by naming the environments for the database where we will release code. Single-click the name Environment 1 and change this to Integration.

    Environment 1 is now renamed to Integration.

  6. Click Run on agent line in the middle section. This will open properties on the right. Change the deployment queue to Default to execute this deployment on your local agent.

    In the middle pane, Run on agent is selected. On the right, in the Run on agent pane, on the Deployment queue drop-down list, Default is selected.

  7. Click Add tasks in the center section. This should bring up the Task catalog. Scroll down to find the Deploy ReadyRoll Database Package task and click Add.

    In the Task catalog, Deploy ReadyRoll Database Package is selected.

    Click Close to close the Task catalog.

  8. The Redgate task should be selected with properties to the right. We will configure these items separately in the next few steps.

    In the left  pane, in red text, Run on agent displays. Under this, in red text, Deploy to is selected. In the right, Deploy to pane, fields are empty.

  9. Click the ellipsis next to Package to Deploy. This will allow us to select a package from our build artifacts. Expand the tree to find the .ps1 file in the Database_Package artifact. This should be named for your project with an _DeployPackage at the end. Select it then click OK.

    Under Select File Or Folder, the following folders are expanded: Linked Artifacts\WideWorldImporters-RR-CI (Build)\Database_Package. In the Database_Package folder, WideWorldImporters-RR_DeployPackage.ps1 is selected. At the bottom, in the Location field, this same path displays.

  10. For the Release Version, we will use a system variable. Enter 1.0.$(Release.Releaseid) in the edit box. The Release.Releaseid is a system variable that is incremented during each release.

    In the Deploy to pane, in the Release Version field, the 1.0$(Release.Releaseid) version is entered.

  11. We will now configure the target database properties. These will vary depending on your particular instance. Replace the values below with those that are appropriate for your instance.

    • Target SQL Server Instance: .\SQL2016 - This is the instance name as your agent will connect to it.
    • Target Database Name: WWI_Integration - From the first part of this lab above.
    • Database Username: $(DeployUser) - A variable we will create.
    • Database Password: $(DeployPwd) - A variable we will create.

    In the Deploy to .\SQL2016 pane, fields are populated with the previously defined settings.

  12. Click the Variables menu item in the release definition. In the Variables list below, enter two new variables:

    • DeployUser: VSTSRelease (created in the first part of this lab)
    • DeployPwd: Use the value you entered for this login in the first part of this lab. Click the padlock to the right to hide the actual value as a secret.

    On the Definition*.Release to Integration page, on the Variables tab, two variables display: DeployUser (with Value VSTSRelease), and DeployPWD (with the value obscured).

  13. Click the Triggers menu item. Continuous Deployment should be selected. This will trigger a release when the CI build completes.

    Under Triggers, the Continuous Deployment check box is selected.

  14. Click Save to save the release. Enter a comment **for the version control of this definition, then click **OK.

    Under Save, in the Comment field, Initial release definition displays.

  15. Test the release by returning to Visual Studio. Right-click the Migrations folder, click Add, then click Script. Enter this code in the migration script.

    CREATE TABLE Sales.Regions
    ( RegionID INT IDENTITY(1,1) PRIMARY KEY CLUSTERED
    , RegionName VARCHAR(200)
    );
    
    

    Click Save, then click Deploy the Project.

    A pop-up displays saying that the Script Status is Deployed.

  16. Go to Team Explorer and the Changes tab. Your new migration script should be listed. Enter a comment, then click Commit All and Push.

    On the Changes tab, the Commit All drop-down menu displays, and the option to Commit All and Push is selected.

  17. Open your VSTS project and quickly navigate to the Build definitions. You should find a build which might be in the Not Started or In Progress states. In the image below, build 5 has not been started.

    On the Changes tab, the Commit All drop-down menu displays, and the option to Commit All and Push is selected.

  18. Quickly move to the Releases page, as this should start as soon as the build completes. You should be able to find a release in progress if you click the refresh button.

    Under Release to Integration / Edit, the Releases tab is selected. Under Release, Release-1 is selected.

  19. Refresh the page until the build is complete. When it is complete, the rectangle next to the release number should turn green. Click the ellipsis to the left and click Open.

    Under Release to Integration / Edit, the Releases tab is selected. Under Release, Release-1 is selected. The ellipsis button is clicked, and from its drop-down menu, Open is selected.

  20. The Summary tab opens and includes some basic details.

    Under Release to Integration / Release-1, the Summary tab is selected, with details displaying. Under Environments, Integration has succeeded.

If you would like more details, you can see the details actions by clicking the Logs menu item.

![Under Release to Integration / Release-1, the Logs tab is selected. In the left pane, both Run on agent and Initialize Job are selected. In the right pane, logs display.](..\assets\manualreleasemigrationbased-jan2018\Lab3.2_Image28.jpg)

We have completed an automated build and release for any changes committed and pushed to our VSTS repository.

Task 3: Implement a continuous release process for QA

We will implement a manual release process for another environment.

  1. In your VSTS project, click the Build&Release menu item at the top and select Releases. Click the plus sign on the left and click Create release definition.

    On the Releases tab, the plus icon is selected, and from its drop-down menu, Create release definition is selected.

  2. You will receive a list of templates to select. We will choose the Empty definition, then click Next.

    Under Create release definition, a list of release templates display, with the Empty template selected.

  3. The next page asks which project and build source to use. The default project and your CI definition should be listed. Check the Continuous Deployment checkbox and click Create.

    On the Create release definition page, under Choose a source that publishes the artifact to be deployed, Build is selected. The Project and the Source (Build definition) fields are set to WideWorldImporters-RR. At the bottom is a check box for Continuous deployment.

  4. This will create an empty release definition with a default name.

    On the Releases tab, in the left pane, under Release Definitions, All release definitions is selected. On the right, in the Definition*.New Empty Definition pane, under Add environment, Environment 1 is selected.

    Click the pencil icon next to the name to edit it. Enter Release WWI as the name.

    The Definition*. field is set to Release WWI.

  5. Click the name Environment 1 and change this to QA.

    On the Triggers tab, the Add Environment field is set to QA.

  6. Click Run on agent in the middle section. This will open properties on the right. From the Deployment queue drop-down list, select Default to execute this deployment on your local agent.

    In the middle pane, Run on agent is selected. In the right, Run on agent pane, on the Deployment queue drop-down list, Default is selected.

  7. Click Add Tasks in the center section. This should bring up the Task catalog. Scroll down to find the Deploy ReadyRoll Database Package task and click Add.

    In the Task catalog, Deploy ReadyRoll Database Package is selected.

    Click Close to close the Task catalog.

  8. The Redgate task should be selected with properties to the right. We will configure these items separately in the next few steps.

    In the left  pane, in red text, Run on agent displays. Under this, in red text, Deploy to is selected. In the right, Deploy to pane, fields are empty.

  9. Click the ellipsis next to Package to Deploy. This will allow us to select a package from our build artifacts. Expand the tree to find the .ps1 file in the Database_Package artifact. This should be named for your project with an _DeployPackage at the end. Select it, then click OK.

    Under Select File Or Folder, the following folders are expanded: Linked Artifacts\WideWorldImporters-RR-CI (Build)\Database_Package. In the Database_Package folder, WideWorldImporters-RR_DeployPackage.ps1 is selected. At the bottom, in the Location field, this same path displays.

  10. For the Release Version, we will use a system variable. Enter 1.0.$(Release.Releaseid) in the edit box. The Release.Releaseid is a system variable that is incremented during each release.

    In the Deploy to pane, in the Release Version field, the 1.0$(Release.Releaseid) version is entered.

  11. We will now configure the target database properties. These will vary depending on your particular instance. Replace the values below with those that are appropriate for your instance.

    • Target SQL Server Instance: .\SQL2016 - This is the instance name as your agent will connect to it.
    • Target Database Name: WWI_QA - From the first part of this lab above.
    • Database Username: $(DeployUser) - A variable we will create.
    • Database Password: $(DeployPwd) - A variable we will create.

    In the Deploy to .\SQL2016 pane, fields are populated with the previously defined settings.

  12. Click the Variables menu item in the release definition. In the Variables list below, enter two new variables:

    • DepoyUser: VSTSRelease (created in the first part of this lab)
    • DepoyPwd: Use the value you entered for this login in the first part of this lab. Click the padlock to the right to hide the actual value as a secret.

    On the Definition*.Release to Integration page, on the Variables tab, two variables display: DeployUser (with Value VSTSRelease), and DeployPWD (with the value obscured).

  13. Click the Triggers menu item. Continuous Deployment should not be selected. This is different from our previous release. We will manually need to create a release here.

    On the Definition*.Release WWI page, the Triggers tab is selected. Under Release triggers, both check boxes are cleared for Continuous Deployment and Scheduled.

  14. Click Save to save the release. Enter a comment for the version control of this definition, then click OK.

    Under Save, in the Comment field, Initial release definition displays.

  15. Click the Release menu item as shown below to create a new release.

    On the Definition*.Release WWI page, on the Triggers tab, the Release drop-down menu displays with Create Release selected.

  16. This will bring up a release dialog where you can select the build that you will release. The most recent release build should be shown, 5 in the case of the image shown. Note that this release is automatically approved, and will be automatically released after you click create. Click Create.

    On the Create new release for Release WWI page, WideWorldImporters-RR_CI (Build) is set to 5. Under Automated deployments, the Environment 1 drop-down menu is set to Automated deployment: After release creation.

  17. The dialog should disappear and just below the menu, a blue bar with a note that the release was created appears. Click the release that is highlighted.

    Under Definition: Release WWI, the Triggers tab is selected, and the message Release Release-1 has been created displays, with the Release-1 link is called out.

  18. You will go to the Summary tab for this release. The release should be in progress.

    On the Release WWI / Release-1 page, on the Summary tab, under Environments, Environment 1 deployment status is In Progress.

  19. If you click refresh a few times, the status will change to Succeeded. If there are any issues, double-check all your settings and use the Logs tab to determine what the issue is.

    On the Release WWI / Release-1 page, on the Summary tab, under Environments, Environment 1 deployment status is now Succeeded.

Summary

In this lab you completed the following tasks:

  • Prepared your local environment_
  • Implemented a Continuous Release process for Integration
  • Implemented a Release process for QA