Automate Dynamics 365 Deployment using Azure DevOps CI/CD (Build & Release Pipeline)

In this blog, I will show you how to implement CI/CD for Dynamics 365 CE and how can we deploy the solution from one source (in my case it is Dev) environment to multiples CE environments.
We Have one Dev and two target environments where I will be deploying the managed build from Dev.

Build Pipeline

  1. Go to the Azure Devops and select your project.

  2. Navigate to the Pipeline and click on the “Create Pipeline”.


  3. Now click on “Use the Classic Editor” and then you can configure the Pipeline through the graphical UI.


  4. Now you need to select TFVC/Repository although I won’t be using any repository in our Pipeline but this is the mandatory step to move forward but you can use TFVC/Repository to save your solution on the server for the backup if you want.


  5. Select “Empty Job” to start building your Pipeline.


  6. You will be seeing the Empty Job screen, Rename the Agent Job.

  7. Click on + and add the new task and search for “Power platform Tools”.

    Note: If “Power platform Tools” is not already installed in your environment, you will get the option to download it from “Marketplace” for free.

  8. Add the following tasks

    “Power Platform Tool Installer” will install the Power platform tool in the Agent Job.

    “Power Platform WhoAmi” this is just to verify the connection of the environment.

    But if the connection string is not already configured it can be done by
    Click on “Manage” as highlighted in above image and you will be redirected to the Project Settings page, there you need to click on “New service connection”



    Now search for Generic connection



    Now you need to provide environment url, username, password and set any connection name



    Now if you go back to the Build Pipeline tab and only refresh the Service Connection drop down you should be able to see the above connection you just have created and you can select it for all the tasks.


  9. Now in Export Solution task we need to provide the solution name, solution output path and I will be exporting this solution as Managed to deploy in to the test environments.



    D365 CE Solution


  10. Now you need to add one more task “Publish build artifact” that will publish the artifact which will be created in previous step
    In “Path to publish”, add the output path of the previous step: $(Build.ArtifactStagingDirectory)



    Now your Build Pipeline is completed and we can start the Release Pipeline!


Release Pipeline

We will use the Release Pipeline to import the exported solution from build pipeline in multiple target environments .

  1. From the side menu go to “Releases” tab and create a New Release Pipeline.


  2. We will start with the Empty Job.


  3. Add an artifact, select the same project and in source select the above created Build Pipeline.


  4. I have renamed the stage name and agent job display name.


  5. Now you need to add below tasks to import the solution in destination environment and I have already discussed the first two steps in Build Pipeline steps.


  6. In import solution task, for service connection I have created the new connection for test environment and select it here and for solution output file select the linked artifacts of build pipeline.




    and append the Artifact and Solution name mentioned in build pipeline.


  7. Now I have added an another stage in the same release pipeline because I want to deploy the exported solution from build pipeline into two different test environments.



    After selecting the empty job I have added the same tasks with different service connection.


    Note: If you want to deploy the build only in one environment you can can skip the above point no 7.

  8. Now in the pipeline tab, select the “continuous deployment trigger” icon and click Enabled. This will automatically trigger the Release pipeline after the build pipeline is run.


  9. Now I have added the “Pre-deployment approvals” for one environment (stage) because as we know this is the automated process but we can keep control of the deployment for any specific environment because sometimes approvals are required from the environment owners or higher management.
    I have added my own user in the Approves list. I will receive an email once the release pipeline is triggered and I can approve or reject the “Deploy Build” stage tasks.

Build & Release Pipeline Test

I have a solution in Dev environment and I want to deploy this solution in our two test environments as a managed, For one environment I have added a Pre-deployment Approval.

I have manually triggered the Azure Build Pipeline


Build Pipeline successfully ran.


In Artifacts our Managed solution file is available.


Now our Release Pipeline is automatically triggered and for one stage I have received an email to approve and for the second stage we didn’t set any pre-validation approval.


Once I approved the build it did get deployed in the destination environment.


I have shared the solution history of one of the test environment.

Now the “ZMAPipelineTest” managed solution is successfully deployed from one Dev environment to two test environments by using the CI/CD (Build & Release Pipeline).

Conclusion

There are several other options available in the Azure Pipelines which I have not used in this blog like setting Solution Version, push solution file in TFVC, send notification if run fails, few more pre and post deployment conditions and many more.
Hope this Article will help you guys to implement CI/CD for Dynamics 365 CE using Azure DevOps and Power Platform.

Send HTML Emails Using MS Flow From Dynamics 365 CE

Introduction

In this blog, I will create a MS Flow and Send the Order related Details to the Customer through the HTML formatted Email from Dynamics 365 CE.

Steps

Here I’m retrieving the Order and Order Lines from Dynamics 365 CE.

Initializing the string variable to create a HTML table ( with basic Inline CSS) for Order Lines to send in an Email.

Adding row dynamically in the table and appending table footer in the end.

I have used the Convert Time Zone action to change the formatting of the retrieve Date fields from Dynamics 365 CE.

Here is the final HTML Email body which will be sent to the customer.

I’m creating an Email Message record and using the Dynamics 365 Email Feature otherwise I could have sent the Email directly from this MS Flow.

Here is the final view of MS Flow and it ran successfully.

HTML Email Message with tabular format Order Lines created in Dynamics 365 CE and Email is sent to the Customer.

Here is how the Customer received the Email in Outlook.

Note
One more thing we can do is create an Email Template in Dynamics 365 and use that in MS Flow and replace the placeholders with HTML chunks. In that way, the end-users can easily update the Email Template/Format whenever they want directly in Dynamics 365.