Deploying an application with Azure CI/CD pipeline to a Service Fabric cluster
Published Dec 08 2022 02:24 AM 1,180 Views
Microsoft

 

Prerequisites

 

Before you begin this tutorial:

 

Configure the Application on the Visual Studio 2019

 

  1. Clone the Voting Application from the link- https://github.com/Azure-Samples/service-fabric-dotnet-quickstart

 

Picture1.png

 

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

PritamSinha_1-1673952278443.png

 

  1. Once you click on Clone button, we can see that application is ready to open on Solution Explorer.

PritamSinha_2-1673952278446.png

 

  1. Now we have to build the solution so that all the dependency DLL will be downloaded on the package folder from NuGet store.
  2. 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.

PritamSinha_3-1673952278457.png

 

  1. After correcting the DLL version, we have to check the application file 'voting.sfproj'

PritamSinha_4-1673952278469.png

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

 

  1. From packages.config file, we can get the MS build version:

PritamSinha_5-1673952278478.png

  1. We must cross check the dotnet version in 'packages.config' of the application and also at the service level.
  2. Like in 'packages.config' is having the net40 but in service dotnet version net472.

PritamSinha_6-1673952278497.png

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

Example –

PritamSinha_7-1673952278515.png

 

  1. Expected error based on above changes –

PritamSinha_8-1673952278530.png

 

  1. We must push our changes to our repo. However, prior that we must take care that we should not push our changes on master branch. We need to create a new branch and push our changes to that branch.
  2. For that, In Visual Studio we can go to Team Explorer

PritamSinha_9-1673952278535.png

 

PritamSinha_10-1673952278587.png

 

  1. After that sync the local branch on DevOps repo.
  2. Now we have to create a Pipeline – Click on New Pipeline

PritamSinha_11-1673952278594.png

 

  1. Then click in Use Classic Editor --> select the repository.

PritamSinha_12-1673952278604.png

PritamSinha_13-1673952278608.png

 

  1. Select the template – search for Service Fabric template-

PritamSinha_14-1673952278617.png

 

  1. After that all the Task will be generated.

PritamSinha_15-1673952278624.png

 

  1. In Agent Specification we need to select the same version as Visual Studio version. Like we have selected the 2019 because we have built the project on VS 2019.
  2. 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”.
  3. In Build solution we must select 2019 as my Visual Studio version is 2019.
  4.  In “Update Service Fabric Manifest” task we can directly change the version in manifest.
  5. In Copy files – we can gather the data from application manifest and application parameters file.

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

PritamSinha_16-1673952278636.png

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

PritamSinha_17-1673952278638.png

 

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

Build Success mail –

 

PritamSinha_18-1673952278646.png

 

 

Build failed mail-

PritamSinha_19-1673952278654.png

 

Release Pipeline-

 

  1. Release pipeline is the final step where application is deployed to the cluster.

PritamSinha_20-1673952278659.png

 

       2. Click on “New Release Pipeline” then again select the template for Service Fabric.

PritamSinha_21-1673952278668.png

PritamSinha_22-1673952278676.png

     

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

PritamSinha_23-1673952278686.png     4. Click on 1 job,1 task

PritamSinha_24-1673952278692.png

      5. Click on stages --> then we have to select the cluster connection. If no cluster connection is created, then click on “New”

 

PritamSinha_25-1673952278703.png

 

     6. Create a Service Connection as given in below image-

PritamSinha_26-1673952278720.png

 

 

PritamSinha_27-1673952278742.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.

 

     7. 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_28-1673952278782.png

 

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

 

PritamSinha_29-1673952278801.png

 

  1. Enable Grant access permission to all pipelines.

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

 

  1. Post above, Deploy Service Fabric application section –

PritamSinha_30-1673952278808.png

 

 

 

  • In Application Parameter – We need to select 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.)
  1. Configure the “Continuous deployment trigger” –

PritamSinha_31-1673952278814.png

 

Then save the config and run the release pipeline.

 

  1. Expected output-

 

PritamSinha_32-1673952278821.png

 

 

 

References-

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

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

 

1 Comment
Co-Authors
Version history
Last update:
‎Jan 17 2023 03:03 AM
Updated by: