In my previous blog, I wrote about how to set up a VSTS build definition. This blog will continue on that by setting up a VSTS release pipeline in Azure DevOps/VSTS. I will assume you got a QA, UAT and a production environment. The package(CRM solutions) from the build automation blog will be deployed to these environments. It will be set up in a very basic way. After that I will elaborate on different other options you can use in Azure DevOps to include in your pipeline.
Dynamics CRM CICD process
The below diagram illustrates the basic flow of the Dynamics 365 CE Workflow process.
In this part, we are going to see the above-highlighted one in detail.
Visual Studio Team Services (VSTS)/ Azure DevOps
Dynamics 365 Build Tools by Wael Hamze
Setting up the variables for the connection to CRM
You can create variable groups in VSTS. This is useful for variables who are related. You will use this to create a group for credentials for your development environment. Later if you implement the automated deployment, you can store the credentials to other environments there too.
In VSTS go to “Build and Release” and select “Library”. Here you can create variable groups.
Next click on “+ Variable Group”. This will take you to a form where you can create a variable group.
Now you give your variable group a name. I will assume you got a test, UAT and a production environment. The package from the build automation blog will be deployed to these environments.So, we will create three connection string for the test, UAT and production environments.
Connection string – AuthType=$(AuthType);Username=$(Username);Password=$(Password);Url=$(Url)
URL- Enter your instance URL.
Username – Enter the username of your instance
Password – Enter the password of your instance
Authtype – Office365
Below is the sample connection string details for your reference
VSTS Release Definition
This release definition will import our packed solution file and then publish the customizations to our Dynamics 365 CE Online sandbox instance(QA, UAT & Production environment).
Once the build definition gets succeded VSTS release definition will trigger automatically and perform the following steps:
You can create a release definition directly from Visual Studio Online(VSTS/Azure-DevOps). To create a new pipeline, you go to Pipelines and then Releases. After that, you click on new and then new release pipeline.
You will get asked to select a template. Those templates are really useful for setting up deployments for azure. For Dynamics CRM deployments there is no template, so you select an empty job.
Next, you will get asked to provide a stage name and stage owner. A stage is an environment, so in our case, we name it “QA”. The owner can be left at default (your account). After you did that you can press the ‘X’ on the top right of the stage tab to close it.
Now you will see the pipeline as below.
You can edit the name of the pipeline and provide the name of your choice. Below that we can see a navigation bar with different tabs.
Artifacts: An artifact is usually the output of a VSTS build definition, but it also has other options like an Azure Container Repository. If you click on “Add an artifact” you can see all options available. In this blog, we will only use the default, which is a build output.
Next is the stages. Here you can copy and add new stages for QA, UAT and production environment.
Adding an artifact
To add an artifact. Click on the “Add an artifact’ button. Now select all the correct details. For Project select your current team project. For source select the build pipeline you made based on the previous blog. Set default version to ‘Default’. Finally, provide the source alias name and click ‘Add’ to finish.
Now, we need to add the task for stage QA. Click on stage “QA”. It will navigate you to the task page as follows:
Now you will be in the task editor. Here you can add tasks similar to the VSTS build definition task editor.
To add a Task click on the + icon next to “Agent Job”. You will get a list of tasks. Search for the “MSCRM Tool installer” and add the task.
Next, add the MSCRM Import solution task and click on the task and add the details like below:
Display Name: Provide the name of your choice(Example: Import Solution to QA) CRM Connection String: Provide the QA connection string variable which we have created earlier. Solution File: Use the three dots at the right corner to select the correct solution (it will show the artifacts of the last successful build, so make sure your solution is there). Checkboxes: According to your needs you can select the below checkboxes
Then next add the MSCRM Publish Customization task as follows:
Setting up the environments
Now that we have set up the QA environment, we need to set up the same for the UAT and production environment as well. Click on “Pipeline” on the navigation bar to go back to the overview. The UAT environment is the same as the QA environment, just different variables (remember we added those in the library). An easy way to create that environment is to clone the QA environment. To do that, hover over the QA test environment and click the icon with the 2 papers as shown below:
It will create a “Copy of QA” stage and you see it connected to the QA stage. Click on it, change the name to “UAT ” and close the tab by pressing the ‘X’ button. Now you have the UAT stage too. The fact that the 2 environments are connected, means that the UAT deployment will automatically start when the QA stage is successfully deployed. Similarly, we need to clone and update the values for the production environment too.
One more thing we need to do is to connect the variables we created at the start of the stages. You do that by clicking ‘Variables’ in the navigation bar and then “Variable Groups”
After that click on the “Link variable group”. Select the variable group and click on Link button as shown below:
VSTS release definition setup is done. Now, we will quickly explore the advanced options in the VSTS release definition.
Triggers define when a stage will be deployed. You can open it by clicking the lightning icon next to a stage.
There are 3 options you can select:
This means the stage will be deployed right after the release is created. This is used to automatically start the first stage in the pipeline after a release is created. In build pipelines, you can set to automatically create a release when the build is completed. If your pipeline has these options enabled, then a successful build will automatically deploy to the first stage.
This means your stage will deploy whenever 1 or more stages successfully deployed. If you select multiple stages, then every stage needs to complete successfully in order to start this stage. Optionally you can select the checkbox to also deploy if the previous stages are “partially succeeded” instead of just “succeeded”
This means the deployment of the stage has to be manually started.
In addition to triggers, you can set approvals. You can configure them by clicking the person icon next to a stage. There are 2 types.
Somebody needs to approve that a stage will be deployed. This approval will trigger when the deployment of a stage is about to start. Either via an automatic trigger or a manual start. Approving the deployment results in the start of the deployment of that stage. Rejecting sets the status of the stage to “not deployed”. Post-deployment approvals
Somebody needs to approve that the deployment of a stage is successful. This approval will trigger after the last deployment task is successfully completed. Approving this results in a succeeded deployment and rejecting it in a failed deployment.
For both options, you can select the approvers and a timeout before it automatically rejects. Also, you can set that if a user manually starts deployment of a stage, that user will not be able to approve the stage. Finally, you can select that approval is skipped when the previous stage was approved by somebody who is an approver of this stage.
Sometimes you may want to start releases on a specific day/time. For that, you can set a schedule. There are 2 options for scheduling resulting in different behavior.
Release Trigger Scheduling
You can set this schedule by clicking the scheduling button below the artifacts. A new release will be created at specific times that are configured. To also deploy to the first stage, make sure that at least one stage has the trigger “After Release”, otherwise it will create a new release but it won’t deploy anything. Also keep in mind a new release will be created, even if there is no new artifact available.
You can set this schedule by selecting the pre-deployment conditions and enabling the ‘Schedule’ option. Here you can define 1 schedule of when to deploy this stage.
I hope now you could have got clear information on how to create the VSTS release definition.
In my next blog, we will see how to enable the gated check-in.
If you are interested in this topic and would like to do some further self-study I encourage you to check out my blog on this.