In previous posts in this blog series on continuous delivery with TFS, our activities have been geared up to deploying the sample application to target servers – or nodes as they are sometimes referred to. But what happens when for some reason you have an environment that’s just not ready to be a target for automated deployment? Maybe the business is just not ready to go that far right now. Maybe there is some technical hurdle you have yet to overcome. On the other hand, you have already experienced how easy it is to manage the configuration of your application with Release Management and how it can bring config order where once there was chaos.
If you find yourself in this position, a possible interim solution is to use Release Management to create what I call Release Ready Builds™ of your application. These are builds which have the correct configuration for the environment they are destined for but which are saved to a staging disk location rather than being actually deployed to target servers. Deployment of these builds is still likely to be a manual process but that’s probably what you are doing already and at least the configuration and any other jiggery-pokery can be taken care of by Release Management.
Create a New Stage
In order to illustrate this technique, I’m going to add a new stage to the deployment pipeline called PRD. This will represent the production environment that for whatever reason I’m unable to deploy to using Release Management automation. Carry out the following in Release Management:
- Add a stage type called PRD from Administration > Manage Pick Lists > Stage Type.
- Create a new Agent-based environment called Contoso University\PRD from Configure Paths > Environments. I linked my web server (ALMWEB01) for convenience but in a non demo context you would probably want to use something more permanent such as a build server. This would of course entail installing the Deployment Agent on that server.
- Add the new environment to the Contoso University\DAT>DQA release path from Configure Paths > Agent-based Release paths. The stage should be fully automated with email notifications turned off and this is probably a good time to change the name of the release path to Contoso University\DAT>DQA>PRD.
- Whilst in the newly renamed Contoso University\DAT>DQA>PRD release path help to speed up the debugging process by making the DQA stage fully automated, removing any Approvers from the Approval Step and turning off email notifications.
- Open the Contoso University\DAT>DQA release template from Configure Apps > Agent-based Release Templates and in Properties change the name to Contoso University\DAT>DQA>PRD.
- On the web server (ALMWEB01 in my case) create a folder called C:\ReleaseReadyBuilds.
Configure New Components
With the PRD stage added, we now need to create new components that will deploy to a folder structure. For the web application, it’s not really all that different because we’re using XCopy anyway as the deployment method so it’s just a case of specifying a new location. The database side of things is more interesting because we need to create scripts rather than run actions against a database. On top of all this, we need a mechanism to ensure that each release is placed in a unique folder. To achieve this, carry out the following steps in Release Management Configure Apps > Components:
- Create a new component called Contoso University\Script DACPAC and configure as follows:
- Source > Builds with application (= selected) > Path to package = \
- Deployment:
- Tool = DACPAC Database Deployer
- Arguments = /Action:Script /SourceFile:”__FileName__” /TargetServerName:”__ServerName__”
/TargetDatabaseName:”__DatabaseName__” /OutputPath:”__OutputPath__” - Parameters > OutputPath > Description = The location for the DACPAC script file
- Create a new component called Contoso University\Script Login & User SQL Script and configure as follows:
- Source > Builds with application (= selected) > Path to package = \Scripts
- Deployment:
- Tool = Windows Common IO
- Arguments = -File ./ManageWindowsIO.ps1 -Action __Action__ -FileFolderName “__FileFolderName__” -DestinationName “__DestinationName__”
- Parameters > DestinationName > Description = Location to copy the file to
- Configuration Variables:
- Variable Replacement Mode = Before Installation
- File Extension Filter = *.sql
- Parameter #1 = LOGIN_OR_USER | Standard | Name of login or user to create
- Parameter #2 = DB_NAME | Standard | Database to set security for
- Create a new component called Contoso University\RRB and configure as follows:
- Source > Builds with application (= selected) > Path to package = \
- Deployment:
- Tool = Windows Common IO
- Arguments = -File ./ManageWindowsIO.ps1 -Action __Action__ -FileFolderName “__FileFolderName__” -DestinationName “__DestinationName__”
- Parameters > DestinationName > Description = Destination name
Configure the PRD Stage
Next we need to configure the PRD stage. To achieve this, carry out the following steps in the Contoso University\DAT>DQA>PRD agent-based release template:
- In order to speed up the debugging process, visit the DAT and DQA stages and click the top left hand icon of every action or component to toggle the skip state:
- In the PRD stage, drag the ALMWEB01 server to the Deployment Sequence.
- Drag the Contoso University\Deploy Web Site to ALMWEB01 and set the parameters as follows:
- Installation Path = C:\ReleaseReadyBuilds\PRD\Web
DATA_SOURCE
= ALMSQL01 INITIAL_CATALOG
= CU-PRD
- Navigate to Toolbox > Windows OS and drag a Create Folder action below Contoso University\Deploy Web Site and set the FolderName to C:\ReleaseReadyBuilds\PRD\Database.
- Navigate to Toolbox > Components and right-click the Components node. Add Contoso University\Script DACPAC.
- Drag the Contoso University\Script DACPAC component below the Create Folder action and set the parameters as follows:
FileName
= ContosoUniversity.Database.dacpac ServerName
= ALMSQL01 DatabaseName
= CU-PRD OutputPath
= C:\ReleaseReadyBuilds\PRD\Database\DACPAC.sql
- Navigate to Toolbox > Components and right-click the Components node. Add Contoso University\Script Login & User SQL Script.
- Drag the Contoso University\Script Login & User SQL Script component below the Contoso University\Script DACPAC component and set the parameters as follows:
Action
= move FileFolderName
= Create login and database user.sql DestinationName
= C:\ReleaseReadyBuilds\PRD\Database\Create login and database user.sql LOGIN_OR_USER
= ALM\CU-PRD DB_NAME
= CU-PRD
- Navigate to Toolbox > Components and right-click the Components node. Add Contoso University\RRB.
- Drag the Contoso University\RRB component below the Contoso University\Script Login & User SQL Script component and set the parameters as follows:
Action
= create FileFolderName
= C:\ReleaseReadyBuilds\$(BuildNumber)
- Drag a second Contoso University\RRB component below the first one and set the parameters as follows:
Action
= move FileFolderName
= C:\ReleaseReadyBuilds\PRD DestinationName
= C:\ReleaseReadyBuilds\$(BuildNumber)\PRD
Check the Stage Works
Navigate to Releases > Releases and manually create a release based on the latest build. Because the previous stages are in skip mode, the PRD stage should finish almost immediately and you should very quickly be able to verify everything is working. Essentially, you should be checking for a folder similar to C:\ReleaseReadyBuilds\ContosoUniversity_Main_Nightly_20150214.8 that contains a PRD folder with Web and Database folders containing our deployable artifacts. The magic that achieves this is the $(BuildNumber)
configuration variable that is one of several that are only available in components. If that’s all working, then you should revisit the DAT and DQA stages and toggle all the components and actions so that they are not skipped, but leave DQA in automated mode. Now run a couple of complete builds from the nightly build definition in Visual Studio, confirming that each PRD build is placed in its own separate folder. Finally, when that’s working, you can revisit the DQA stage and return it to its manual status.
By way of finishing off, I want to stress that you should be doing everything possible to use the full automation capabilities of Release Management to deploy your application along the whole delivery pipeline. But when you really do have a problem with a particular stage, hopefully the technique I’ve illustrated here will tide you over.
Cheers – Graham
The post Continuous Delivery with TFS: Save to a Folder for Stages You Can’t Yet Deploy to appeared first on Please Release Me.