Set Up CI/CD of Microsoft Dynamics CRM Solutions

Microsoft Dynamics CRM is a Customer Relationship Management software by Microsoft. The main areas it focuses on are sales, marketing, and help desk. Microsoft has been promoting Dynamics CRM as a Customer Relationship Management and advised to use it once proprietary. It can also be customized by using an Open Source (.NET based) framework. 

Here we will discuss the automated deployments (Continuous Integration and Continuous Deployment) of MS Dynamics CRM on On Premise and Cloud Using Azure DevOps Pipelines. 

Types of CRM Solutions: 

MS Dynamics Solution:  

An MS CRM solution is a package that is customized or developed by customers to extend the CRM. Any update that needs to be done on a Microsoft CRM can be packaged in a solution and then deployed on the target organization. 

Managed Solution: 

A solution that is finalized and planned to be distributed is known as a managed solution. Once deployed on a target organization, it cannot be modified on the target organization, and when uninstalled, all the customizations done would be rolled back.  

Unmanaged Solution: 

A solution that is still under development and not aimed to be delivered is called an unmanaged solution. It can be modified even on the target organizations. It contains all the components that were customized or updated in the development organization. Once installed on an organization, the customization done by the unmanaged solution cannot be rolled back, even if the solution is uninstalled.  

Continuous Integration and Continuous Deployment Using Azure Pipelines: 

Azure DevOps allows us to use its build and release pipelines to set up CI/CD of CRM Solutions.  

Continuous Integration: 

Azure DevOps Build Pipelines are used for continuous integration. CI triggers when there is a commit in a specified branch and repo. In the case of Pipeline for Microsoft Dynamics CRM, the build pipeline will be used to export our CRM solution from the specified source organization. Using Azure DevOps, you have plenty of tasks for exporting a CRM solution. You can also use a PowerShell Script for this purpose. 

Continuous Deployment: 

Continuous Deployment is, whenever a build pipeline is completed successfully, the artifacts published by that build pipeline should be deployed to the destination organization. Microsoft Azure DevOps Release Pipelines can be used for Continuous Deployment of Dynamics CRM Solution. 

Setting up a Build Pipeline (Continuous Integration): 

  • Navigate to the project you want to create pipeline for. 
  • Click on the pipelines, select pipelines, and Create a new pipeline using the New Pipeline Button. 

image001

  • Click on the Use Classic Editor  

image003

  • Specify the Repo where your code resides and to which you want to Enable CI and create the pipeline with Empty Task.

image005

  • Enable Continuous Integration of Azure Pipelines. Click on the trigger button and check the box “Enable Continuous Integration.

image007

  • Add the Task for Power DevOps Tool Installer. 

image009

 

  • Now add the task for Solution Export. You can use the task that you want to;, we will be using the following one. 

image011

 

  • Now provide the connection string and the name of the solution to the task. The connection string would be like this:  

AuthType=Office365; Url=<url to CRM Server>; UserName=<[email protected]>;Password=<*******>”.  

You can also specify the task whether you want to export the solution as Managed or Unmanaged. Keep in mind or copy the Output Path it would be needed in the next step. 

image013

  • Once the Microsoft Dynamics CRM solution is exported, you need to publish it as an Artifact. Publish Build Artifact is an Azure DevOps Build Pipeline task that can be used to do so. 

image015

  • Paste the output path in the “Path to Publish” you copied in the previous task to Publish the CRM Solution an artifact. You can also rename the artifacts name. This name would be used in the release while importing the CRM solution.  

image017

Setting up a Release Pipeline (Continuous Deployment): 

  • Navigate to the project where you want to set up the Continuous Deployment. Click on the Pipelines, Select Releases and Create New Release Pipeline. Start with the Empty Job. 

image019

  • Link the build pipeline to the Continuous Deployment pipeline by using Add an Artifact button.  

image021

  • Enable CD by using the Continuous Deployment Trigger Button. 

image023

  • Now add the steps to the release pipeline by clicking on the Job, Task button under the Stage name. 

image025

  • Add the Power DevOps Tool Installer task. 

image027

  • Add the Import Solution task. 

image029

  • Add the connection string for the Destination org where you want to Deploy Microsoft Dynamics 365 solution. Also, link the solution file that was published as a build artifact in the linked pipeline. The path name would be like  

$(System.DefaultWorkingDirectory)/<BuildName>/<ArtifactName>/<SolutionFile>.zip 

image031

  • Now add the Publish Customization task to your Release.  

image033

Controlling Deployment Pipelines through PowerShell Script: 

You can control the Continuous Integration and Continuous Deployment of MS Dynamics Solution by adding a PowerShell script in your source. Add a PS with the information like the Source organization from where the solution would be exported, Solution Name, Username, and the Destination organization where you want to deploy. You can also add a switch “Deploy CRM” to control either the CRM should be deployed on commit or not. Copy the PowerShell Script to control the Continuous Integration and Continuous Deployment of MS Dynamics Solution and commit this as a .ps1 file in your repo.  

$global:config = @{    

#SourcE 

 

    Username = [email protected] 

    URL = “https://xyz.crm.dynamics.com/org012evc9” 

    DeployCRM = “Yes” 

    SolutionName = “fordemo” 

    runtest      = “Yes” 

      

#Dest 

 

    DestUsername =  [email protected] 

    DestURL = “https://alphaboldai0.crm.dynamics.com/org6b7177f6” 

} 

 

$CRMDeployment = $Global:config.DeployCRM 

$SolutionName = $Global:config.SolutionName 

$Username = $Global:config.Username 

$URL = $Global:config.URL 

$runtest = $Global:config.runtest 

$DestUsername = $Global:config.DestUsername 

$DestURL = $Global:config.DestURL 

 

Write-Output (“##vso[task.setvariable variable=DeployCRM;]$CRMDeployment) 

Write-Output (“##vso[task.setvariable variable=SolutionName;]$SolutionName) 

Write-Output (“##vso[task.setvariable variable=URL;]$URL) 

Write-Output (“##vso[task.setvariable variable=Username;]$Username) 

Write-Output (“##vso[task.setvariable variable=runtest;]$runtest) 

Write-Output (“##vso[task.setvariable variable=DestUsername;]$DestUsername) 

Write-Output (“##vso[task.setvariable variable=DestURL;]$DestURL) 

  • Copy this PS and commit in your repo as a PowerShell Script file. 
  • In your build pipeline Publish this file as a build artifact 

image035

  • Now in the Release pipeline, run this PowerShell Script on top of each task. It will set the Global Variables on the agent reading the information you provided. Then you can replace the username, solution name, and the organization name with the global variables.  

image037

image039

  • To use the “Deploy CRM” switch, you can find “Control Options” under each task. Use Custom Conditions and Specify the Condition as “eq(variables[‘DeployCRM’], ‘Yes’) 

image041

Final Thoughts: 

Microsoft Azure is a best option to use when you want to set up CI/CD of a Microsoft Dynamics Solution because it provides flexible Build and Release Pipelines. MS Azure has a vast marketplace loaded with bundle of tasks to choose within your pipelines, when comes to the Continuous Integration and Continuous Deployment of any application. It also allows you to control your deployment via PowerShell Scripts, you can supply the solution name, source and destination organizations name, credentials along with a switch that will determine if you want to trigger the build or release pipeline on commit.   

Posted in: CRM

Leave a Reply

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