If you are using Service Fabric, most probably you are deploying through Visual Studio or having a build in TFS. However, there is an option with Jenkins which is not documented, but easy to set up. The benefit of it is that you can achieve continuous delivery process and keep a track of the changes in the script. There are some tricks that I’ll cover on this blog

First – 64 bit. Jenkins by default uses the 32 bit JDK. That’s ok in most cases, but not for the Service Fabric scripts, as they run in 64 bit only. You can see details on this blog post: http://blog.geo.bg/2017/11/12/64-bit-jenkins

Second – certificates. Most probably you are securing the deployment with a certificate. You need to put your certificate in the right store, so Jenkins can “see it”. There are different methods to do that, so I’ll not go into details, as it may be different for you anyway. Make sure to do that, though, as the deployment may not work without that. I used the script from PowerShell:

Import-PfxCertificate -Exportable -CertStoreLocation Cert:\LocalMachine\My -FilePath "{PATH TO THE PFX FILE}" -Password (Read-Host -AsSecureString )

Note: If Jenkins is running as local system account you can use pstools to register the certificate:

psexec -s -i cmd.exe

Third – Update the PowerShell script for deploy. You can see details on this blog post: http://blog.geo.bg/2017/11/12/powershell-script-for-service-fabric-deployment-in-jenkins

Fourth – Jenkins script. I used the Pipeline, as I like the option to keep my script in a git repository. That’s all you need to have a full build/deploy process.

I downloaded NuGet to C:\tools folder and moved the deployment script and the configurations there. I don’t think those should stay in the VS project anyway.

node {
    stage('Clone sources') {
            git url: '{GIT URL}', branch:"develop", credentialsId:"{CREADENTIALS_ID}"
    }
    stage('Resolve references') {
        bat ('c:\\tools\\nuget.exe restore  {PATH OF THE SOLUTION FILE}')
        //This line is required only if you are using ASP.NET Core. It's obsolate, but in some cases it helps
        bat ('dotnet restore Services/Web/Source/SharePlusEvo.sln')
    }
    stage('Build') {
        bat('"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\amd64\\msbuild" {PATH OF THE SOLUTION FILE} /nologo /nr:false /t:"Clean" /fl  /p:platform="x64" /p:configuration="Debug" /p:VisualStudioVersion="15.0" /m')
        bat('"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\amd64\\msbuild" {PATH OF THE SOLUTION FILE} /nologo /nr:false /fl /p:platform="x64" /p:configuration="Debug" /p:VisualStudioVersion="15.0" /m ')
    }
    stage('Package'){
        bat('"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\amd64\\msbuild" {PATH OF THE SERVICE FABRIC PROJECT FILE} /t:Package /p:platform="x64" /p:configuration="Debug"')
    } 
    stage('Deploy'){
        powershell('C:\\tools\\Scripts\\Deploy-FabricApplication.ps1  -ApplicationPackagePath "{SERVICE FABRIC PROJECT FOLDER}\\pkg\\Debug" -PublishProfileFile "{PATH OF THE PUBLISH PROFILE FILE}" -OverwriteBehavior Always')
    }
}

Let me know if you have any questions or comments how I can improve the blog.

Thanks,
George

Image for the social media

Categories: DevOpsService Fabric

Leave a Reply

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