Saturday 29 September 2018

CI/CD with Visual Studio Online

We are going to automate our build and deployment process with Visual Studio Team Service for micro-services which are developed in Azure Service Fabric Framework.

We cover the following steps for CI/CD with Visual Studio Online,
  • Generate build and published artifacts with each checked-in
  • Release artifacts while new build available with Pre-deployment approvals

Create a build definition

Logged-in to the Visual Studio Team Service and go to the Build and Release tab, then clicking on the New button from the page which showing several templates for generating build. we select Azure Service Fabric Application template from available options




After clicking on Apply button, Visual Studio Team Service automatically generate tasks which require to build Service Fabric Application.




But VSTS wants some inputs from us for Agent queue field, we select Hosted VS2017 option to build our Service Fabric Application.





From Triggers tab, we enable continuous integration option.

Now we are good to go for generating build which trigger based on each checked-ins. We save our build definition and queue build. 

Our build failed due to following error,

Error : The OutputPath property is not set for project 'Authentication.Business.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Release' Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project

Some of our projects in Service Fabric Application are configured with Any CPU option, and in VSTS set the Platform target variable to x64 which breaking our build.

Going back to build definition edit tab, and setting up variable of BuildPlatform to blank so that VSTS automatically identify the appropriate Platform for Service Fabric Application.



Clicking on Save & queue build,

This time our build succeeded and build artifacts are generated in drop folder in Visual Studio Team Service Server.

Now our next step is deploying latest artifacts to the Service Fabric environment which is hosted in Azure.


Create a release definition
Go to Release tab, and clicking on + Icon and select Create release definition option which landed us on this page,

We select Azure Service Fabric Deployment template which create deploy service fabric application task,

We need to tell VSTS about info of the Azure cluster infrastructure by setting up the connection so, that VSTS can deploy latest available artifacts to our azure service fabric cluster.


Clicking on Manage button which shown near Cluster Connections option which redirect us to Service Endpoint tab from Setting in VSTS.
Select Service Fabric option from dropdown.


There are three ways to connect Service Fabric,
  1. Certificate Based
  2. Azure Active Directory credential
  3. Others
Here we going to the Certificate Based approach to connect with our service fabric cluster which is hosted on Azure infrastructure.




·         Connection name: Name of your cluster connection name (Ex. - Azure-SF-Connection)
·         Cluster Endpoint: Micro service cluster endpoint format will be tcp://{your-cluster-name}.{azure-region-name}.cloudapp.azure.com:19000 (Ex. - tcp://microcluster.eastus.cloudapp.azure.com:19000)
·         Server Certificate Thumbprint: Server Certificate Thumbprint which used to secure Cluster in Azure (Ex. - 6B5F7C79B7E64FF1WDF87BEC9E8D32C7A5QQ9819)
·         Client Certificate: Server Certificate in Base64 String (Ex - base64 string format)
·         Password: If your Server Certificate have Password which need to be add our here. (Ex - XYZ)

We can obtain base64 string of Client Certificate using below PowerShell script,
[System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes("C:\certificate.pfx"))

From script it's convert Client Certificate named "certificate.pfx" which is on C: drive into the base64 string.



Coming back to the Release definition task and dropdown showing the values of cluster connection and we set that connection & rest of the options which shown in red marks to the azure service fabric task.



And our Release pipeline is,



After checked-in in the branch, VSTS will pick up the latest source and build artifact and based on latest artifact will deploy in Service Fabric Application on Azure. 




No comments:

Post a Comment

Xamarin - Cross Platform Mobile Development

Xamarin - Cross Platform Mobile Development Xamarin is one of the most popular cross-platform frameworks at the moment. Xamarin devel...