Saturday, 27 September 2014

Setup Servers & Environments for VS 2013 Release Management

Another prerequisite to getting VS Release Management to automate release workflow is setting up the Servers & Environments. To register as a Server in VS Release Management, machine should be first installed with Microsoft Deployment Agent.
001
Note - The above view in Configure Apps only available until all mandatory steps are done only. It disappears after all mandatory configurations are once done. Items shown in above can be accessed in different tabs and section in the release management client.
1. Registering Server
In VS Release Management Client click on Configure Apps –> Add Servers link or Click on Configure Paths –> Servers
002
Click on New –> Scan For New to find available Deployment Agent installed and configured machines.
003
Optionally enter a prefix or suffix and Click on Register button to register the server found.
004
 005
Machine get registered as a server and initially shown as offline.
006
Once the heartbeat is received from deployment agent to release management server, machine shows as ready.
007
Next step is creating environments, with successfully registered servers.
008
2. Setup environment
Click on Environments link in Configure Apps  or in Configure Paths click on Environments.
009
Click on New to create new environment.
010
Provide a Name and click on Link Existing to link registered servers to the environment.
011
Select the available server(s) and click Link.
012
You can add tags. These tags are useful when setting up release templates. The tag can be used instead of Server name which allows copying templates workflow steps easily between different stages in the release template.
First environment is created as DevInt (Dev. Integration)
013
Stage Type Security can be used to restrict the stages in release path that the environment can be used.
013_1
For demo purpose QA and Production environments set up with same Server. In practical scenario these will be different servers. and environment may contain multiple servers linked.
QA
014
Production
015
Servers and Environments configuration is successfully completed.
 016
017

Tuesday, 16 September 2014

Using TFS Work Items - Part 2 & TFS Builds

This is the second part of the TFS Work Items session by me @ MSFT Sri Lanka. First session is available here.


Monday, 8 September 2014

Tool to Execute Multiple SQL Scripts – VS 2013 Release Management – Part 1

Is it possible to execute set of SQL scripts downloaded to Deployment Agent in VS 2013 Release Management? Yes. But this requires a custom tool and an action.
Let’s see how we can do this step by step.
As the first step write a PowerShell script capable of executing batch of scripts in a transaction.
 Param([string]$ServerInstance, [string]$DatabaseName, [string]$ScriptPath)   
  $ErrorOccured = $false   
  #Executing following snapins to Invoke-SqlCmd    
  Add-PSSnapin SqlServerCmdletSnapin100 -ErrorAction SilentlyContinue   
  Add-PSSnapin SqlServerProviderSnapin100 -ErrorAction SilentlyContinue   
  Write-Host "Executing patch scripts of path: $PatchScriptsPath"   
  Start-Transaction -RollbackPreference Error   
  Use-Transaction -TransactedScript {    
   foreach ($file in Get-ChildItem -path $ScriptPath -Filter "*.sql")   
   {    
    Write-Host Executing: $file.name ...   
    $ScriptPath = $ScriptPath + "\" + $file.name   
    Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $DatabaseName -InputFile $ScriptPath -ErrorAction SilentlyContinue -ErrorVariable errors   
    foreach($error in $errors)   
    {   
     if ($error.Exception -ne $null)   
     {   
      $ErrorOccured = $true   
      Write-Host -ForegroundColor Red "Exception: $($error.Exception)"   
     }   
    }   
   }   
  } -UseTransaction    
  if ($ErrorOccured)   
  {   
   Undo-Transaction   
   throw "Error occured while Executing SQL Scripts."   
  }   
  else   
  {   
   Complete-Transaction   
   Write-Host Successfully executed all SQL scripts.   
  }  

Next create a tool in Release Management Client as shown below.

a1

Parameters are

NameTypeDescription
ServerInstanceStandardSQL Server Name with Instance Name
DatabaseNameStandardName of the database the scripts should run
ScriptPathStandardLocation of the scripts to be executed


Create an action as shown below using the tool created above.

a2

This action can be used in a release template as shown below to execute SQL scripts in a transaction.

a3



On failure scripts actions will not be committed and release management action will fail. In Part 2, I will show this tool in action.

Wednesday, 3 September 2014

Setup Stage Types in VS Release Management

Stage Types are used in VS Release Management to define stages that are going to be utilized in Release path. In other words stage types are the release will transition through. This is one of mandatory configuration settings in VS Release Management.
001
Click on Stage Types link as shown in above picture, in Release Management Client (This is available only when initial configurations are not complete) or in the Administration tab –> Manage Pick Lists to configure Stage Types.
002 
It is possible to add stages such as DevInt, QA, UAT, Production etc as shown below.
003
Another pick list that can be added is, Technology Types, which is used to categorize the applications by technology stack when defining Servers and Environments. This is optional configuration in VS Release Management.
004
Technology Type such as SQL, Web etc. can be added.
005
Once added above Configure Apps tab shows summary of configured items.
006

Friday, 22 August 2014

Using TFS Work Items – Part 1

This is a session conducted by me @ MSFT Sri Lanka.

Configure TFS Connection for VS 2013 Release Management

Another optional configuration for VS Release Management is TFS connections. TFS Connections are optional because Release Management is capable of using package/payload built by any other build system.
If TFS is used in an organization it can be integrated with VS Release Management to provide as end to end solution, which tracks TFS based Requirements to Production Deployments.
With VS Release Management TFS can be integrated at the project collection level. This allows integration of project collections from different TFS servers with a single VS Release Management Server. In other words VS Release Management Server is capable of managing releases, using builds done manually, any other build system or any number of TFS build Servers.
001
First step is to setup an account to integrate TFS and VS Release Management Server.
004
 005
In Administration tab of the VS Release Management Client go to Manage TFS and click on New button.
002
003
Select the TFS Integration account.
006
Provide the TFS Project Collection details.
007
Click on verify to check the connection to Project Collection.
008
Access denied. This is because the TFS integration account is not having required permissions in the Project Collection. Release management installation guide specifies the account requirement as below.
image
To enable the TFS integration account to be used to connect all the project collections with release management server, the TFS integration account should be added to “Team Foundation Service Accounts”.
009
This TFS group is not allowing to directly add remove users with TFS Console Admin. The option is to use the g+ command as shown below.
TFSSecurity /g+ groupIdentity memberIdentity [/collection:CollectionURL] [/server:ServerURL]
Example
tfssecurity /g+ "Team Foundation Service Accounts" n:ALM\rmtfsint ALLOW /server:http://tfs:8080/tfs
Above command should be executed in Developer Command prompt of VS. To find the Developer Command prompt for VS 2013 in Windows 8.1 right click on VS Shortcut and open file location.
011.
Open the VS Tools folder
012
Pin the Developer Command Prompt for VS2013 to Start Menu.
013
Using VS Developer command prompt execute g+ command
tfssecurity /g+ "Team Foundation Service Accounts" n:ALM\rmtfsint ALLOW /server:http://tfs:8080/tfs
014
This will add the TFS integration account to "Team Foundation Service Accounts"
015
016

In Release Management Client connection to TFS project collection can be successfully verified and saved.
017
Next step is to define the Release Management Stages.
018


Sunday, 17 August 2014

Configure SMTP for VS 2013 Release Management

After setting up Release Management Server, Client and Deployment Agent(s) configurations steps for VS Release Management should be done.
First step is setting up SMTP. This is a optional step, but necessary to configure for sending email notifications in release management workflows.
“Configure Apps” tab shows a guide for configurations, when VS Release Management Server is initially setup.
001
Click on “SMTP Server Settings” in “Configure Apps” tab or Click on Administration –> Settings to navigate to the settings tab.
002
Provide below (reference VS Release Management User Guide)
Server Name – Fully qualified address of the SMTP server to use.
Port – Optional. Port to be used when connecting to the SMTP server to send email notifications.
User Name – Optional. Name of the identity to be used to authenticate against the SMTP services.
User Password – Password of the identity to be used to authenticate against the SMTP services. Mandatory if User Name is specified. Otherwise, optional.
Sender Address – Email address as it will appear in the email client. No replies are expected to be sent to this address. Therefore, the email or text can be anything.
003
Once above configuration done Release Management Server is ready to send email notifications.
004

Tuesday, 5 August 2014

Custom Action to Run SQL Script With Parameters in VS 2013 Release Management Deployment Agent

How to pass parameters to SQL script running from VS 2013 Release Management? Let me show you step by step.

First we need a SQL Script to Run as a test. Here is a very simple SQL Script written in SQLCMD mode.
INSERT INTO [dbo].[Customer]
           ([Id]
           ,[Name])
     VALUES
           ($(Id)
           ,'$(Name)')
GO
This script is inserting a record to a table with two columns. The script cannot be directly executed in SQL Management Studio since the $(Id) and $(Name) variables are not set. If tried will get below error.
a2 
To test the script run the below command in command prompt.
sqlcmd -S "POC-DOLPHINQA" -d "TestDB" -i "C:\Temp\TestSQL.sql" -v Id=3 Name="Chandrasekara" –b
a3
This adds a row to the table successfully.
a4
To create a new Action in the VS 2013 Release Management –> Log on to Client and go to Inventory tab and select Actions –> Click New
Create an action as shown below.
 a1
Arguments should be
-S "__ServerName__" -d "__DatabaseName__" -i "__ScriptName__" -v __Params__ -b

This will add below parameters to the action

ServerName – SQL Server Instance Name
DatabaseName – Database Name the script should run
ScriptName – Script to execute with full path (In deployment machine. Copying script to deployment machine can be done using XCOPY Deployer)
Params – Parameters for the SQL Script

Now this action can be used in Release template.
a2
Let’s try a release.
a3
The new action execution succeeded.
a2
Table is added with new record.
a4
This custom action can be used even to execute script while dynamically changing target DB, tables, columns etc. using SQLCMD syntax.
For example
Use $(MyDatabaseName)
SELECT x.$(ColumnName)
FROM Person.Person x

Popular Posts