Deploying an application with Azure CI/CD pipeline to a Service Fabric cluster

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

Prerequisites

 

Before you begin this tutorial:

 

Configure the Application on the Visual Studio 2019

 

1. Clone the Voting Application from the link- https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-tutorial-deploy-app-with-cicd-vsts#download-the-voting-sample-application

 

PritamSinha_0-1670482577214.png

 

2. After that we can enter link to clone the voting application

 

Picture2.png

 

3. After clicking on the Clone button, we can see that application is ready to open on Solution Explorer.

 

Picture3.png

 

4. After that we have to build the solution so that all the dependency DLL will be downloaded on the package folder from Nuget store.

 

5. We need to cross check the Nuget package solution to find if any DLL is deprecated. If so, then we need to update all older version of DLL

 

Picture4.png

 

6. After correcting the DLL version, we have to check the application folder a 'voting.sfproj'

 

PritamSinha_0-1670486256304.png

 

Note – For Visual studio 2022 tool version will be 16.0 and we have to update the MS build version everywhere in the file 'voting.sfproj' file.

 

7. From where we can get the MS build version

 

Picture6.png

8. We must cross check the dotnet version in 'Package.config' of the application and also at the service level.

 

9. Like in 'Package.config' is having the net40 but in service dotnet version net472.

 

Picture7.png

 

10. We have to manually add the reference of MS build in service project file.

Eg -Picture8.png

 

11. Expected error based on above changes –

 

PritamSinha_0-1670486502147.png

 

12. We must push our changes to our repo. Before that we must take care that we should not push our changes on master. We must create a new branch and push our changes to that branch.

 

13. In Visual Studio we can go to Team explorer.

PritamSinha_1-1670486550219.png

 

14. After that sync the same repo on DevOps repo.                                                       PritamSinha_3-1670486626325.png

 

15. Now we have to create a Pipeline – click on New Pipeline

Picture13.png

 

16. Then click in Use Classic Editor --> select the repos

Picture14.png

 

PritamSinha_5-1670486851768.png

17. Select the template – search for service fabric template-

Picture16.png

 

18. After that all the Task will be generated.

PritamSinha_10-1670487551432.png

19. In Agent Specification we must select the same version as Visual Studio version. Like we have selected the 2019 because we have built the project on VS 2019.

 

20. Use NuGet latest stable version. At time of this blog creation NuGet version is 5.5.1. Also uncheck the checkbox “Always download the latest matching version”.

 

21. In Build solution we must select 2019 as my visual studio version is 2019.

 

22. In “Update Service Fabric Manifest” task we can directly change the version in manifest.

 

23. In Copy files – we can gather the data from application manifest and application parameters file.

Please refer below image for above points (19-23)

Picture18.png

 

24. Enable continuous integration checkbox, so that whenever we do any commit on the repo Automatically the build pipeline is triggered. 

PritamSinha_13-1670487743209.png

 

 

25. We can add some static variables while executing the pipeline by putting the value in variable.

Build Success mail –

 

Picture20.png

 

Build failed mail-

Picture21.png

 

Release Pipeline-

 

  1. Release pipeline is the final step where application is deployed to the cluster. PritamSinha_15-1670487861862.png

 

  1. Click on New Release Pipeline.  Then again select the template for Service Fabric.PritamSinha_17-1670487978814.png

    Picture24.png

 

  1. Then add the Artifact by selecting the correct build pipeline.
     

    Picture25.png

  2. Click on 1 job,1 task

 Picture26.png

 

  1. Click on stages --> then we have to select the cluster connection. If no cluster creation is created, then click on new
     

    Picture27.png

  2. Create a service Connection as given in below image-PritamSinha_0-1670489641049.png

     

Picture29.png

 

Note: - For Azure Active Directory credentials, add the Server certificate thumbprint of the server certificate used to create the cluster and the credentials you want to use to connect to the cluster in the Username and Password fields.

 

  1. How to generate the Client certificate value –
  • Open to PowerShell ISE with Admin access.
  • Paste the command- [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes("C:\Users\pritamsinha\Downloads\certi\certestuskv.pfx").
  • Paste the output in the same PowerShell workspace area and remove all the space from beginning and end. 

PritamSinha_0-1670488367086.png

 

      8. In case of some error with base 64 value then deployment will fail-

PritamSinha_1-1670488415735.png

      9. Enable Grant access permission to all pipelines.

Note – incase when cluster certificate is expired, and we have updated the cluster certificate then we need to update the thumbprint and client certificate value.

 

     10. Then come to Deploy Service fabric application section –

Picture32.png

 

  • In Application Parameter – we must set the target location of the file where the application parameter file is placed.
  • Enable compressed package so that application package will be converted to zip file.
  • CopyPackageTimeoutSec-Timeout in seconds for copying application package to image store. If specified, this will override the value in the published profile.
  • RegisterPackageTimeoutSec -Timeout in seconds for registering or un-registering application package.
  • Enable the Skip upgrade for same Type and Version (Indicates whether an upgrade will be skipped if the same application type and version already exists in the cluster, otherwise the upgrade fails during validation. If enabled, re-deployments are idempotent.)
  • Enable the Unregister Unused Versions (Indicates whether all unused versions of the application type will be removed after an upgrade.)

  11. Configure the Continuous deployment trigger –

PritamSinha_2-1670488514671.png

 

    Then Save the config. And run the release pipeline.

 

    12. Expected output-

 
 

Picture34.png

 

References-

Azure pipeline reference link -https://learn.microsoft.com/en-us/azure/devops/pipelines/get-started/what-is-azure-pipelines?view=azure-devops

Service Fabric Azure CICD pipeline doc- https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-tutorial-deploy-app-with-cicd-vsts

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.