1
votes

I have TFS 2015 and i was able to automated the build process from the branch and get the files from the drop folder as shown below: enter image description here

It has release for multiple projects like Web API and Windows Service

I want Azure VM on which i want to automate the deployment process - continuous delivery.

  1. Deploy the Web API on IIS on Azure VM
  2. Deploy the Windows Services On Azure VM.
  3. Run Scripts SQL.

I have credentials of Azure VM. How i can perform the three above steps.

2
What's the Web API are you specific in the question? Could you show an example?PatrickLu-MSFT

2 Answers

1
votes

I have worked on a similar problem in the past so can probably help you out (MSFT, if it helps).

Web Api on IIS on Azure VM

This is almost completely automated in the form of WinRM - IIS Web App Deployment task that you can find and add in your release definition. The link provides complete instructions on what parameters to provide and tweaks to be done for Azure VM compared to on-premise ones. There are a few prerequisites to running this task, like installing and configuring IIS on the VM which the documentation discusses in detail. As a necessary input to this task, you need to provide the web deploy package which I am assuming was generated as your build output. If not, you can refer to this SO post to get the required output. If you have parameters like connection strings that you wish to modify at deploy time, using a parameters.xml file in the above task.

Windows Service on Azure VM

There is no completely automated task for this requirement, but it is pretty straight-forward. It can be achieved by using the PowerShell on Target Machines task along with Azure File Copy task. For the first task, all that is required as input is the .exe of the windows service that you wish to deploy, which should be generated as the output of your build process (build artifacts). Much of the remote machine inputs for this task is similar to the previous one so you should not have any problem there. You will need to check-in the Powershell script that does the actual windows service installation, in your source code as part of the same windows service project (copy local = True). This will ensure that as the build output, you will have access to the powershell script which you can use in the second task. Azure File Copy is required to copy your powershell script to the Azure VM so that the Powershell task can execute it. Let's assume you copied the powershell script to a folder C:\Data\ on the Azure VM.

$serviceName = "MyWindowsService"
$exeFullName = "path\\to\\your\\service.exe"
$serviceDisplayName = "MyWindowsService"
$pss = New-Service $serviceName $exeFullName -DisplayName $serviceDisplayName
        -StartupType Automatic

Add this content to the checked in powershell file and name it installWindowsService.ps1. Then in the powershell task provide the path of the powershell file to execute as C:\Data\installWindowsService.ps1.

Run SQL Scripts on Azure VM

I haven't personally worked on this so the best I can do is point you in the right direction. If you are using DACPAC for your SQL deployment, you can use the WinRM - SQL Server Database Deployment task. If you just intend to execute scripts, use the remote powershell task from above and refer this post that will help you with running SQL commands through powershell script

1
votes

Seems you want the CD release process picks up the artifacts published by your CI build and then deploys them to your IIS servers/Windows Services on Azure VM.

If you've just completed a CI build, then you should create a new release definition that's automatically linked to the build definition.

Open the Releases tab of the Build & Release hub, open the + drop-down in the list of release definitions, and choose Create release definition.

enter image description here

  • For 2, write a powershell script to handle this, ensure build outputs were available to copy from the ‘Drop’ folder on the build and that they are copied to C:\xxx\ on the target VM(s). More detail steps please refer this blog.
  • For 3, you could use Azure SQL Database Deployment task. Either select the SQL Script file on the automation agent or on a UNC path that is accessible to the automation agent. Or directly enter the InLine SQL Script to run against the Azure SQL Server Database. Also take a look at the tutorial.

Maybe not all the task is fully Compatible with TFS2015 version, you could upgrade your TFS version to get more new features or customize your own build/release task to handle it.