D365 F&SCM CI/CD using Build VM
In this blogpost we will go through the process of configuring the CI/CD for D365 F&SCM through Build VM and Azure devops Pipelines. We also have an option to achieve CI for building and creating deployable packages for x++ models through Azure hosted agents which is described here.
We will get through this journey in the following 3 steps. Also make you finish the process defined in this blog as prerequisite.
Deploy/ Configure a Build VM -> CI Setup -> Configure Build/Release Pipelines -> CD setup
Deploy/Configure a Build VM
The article Deploy development environments describes how to deploy developer environments. Use the same flow to deploy a build environment. As you are going through the deployment or configuration wizard, when prompted to Select a Topology, select DevTest then select a Build and Test topology.
As part of the deployment wizard, you can configure the build agent name and build agent pool.
Click Advanced settings, select Azure DevOps/Visual Studio Team Services, Enter the following Details:
- Build Agent Name: Friendly name for build agent on Azure DevOps, you can keep this same as Environment name.
- Build Agent Pool: specify build agent pool name which should be used for build machine deployment. By default, there will be the default pool. Agent Pool should be created in your devops project linked to LCS. To create Agent Pool, go to Azure DevOps>Organization Settings>Agent Pools> Add
3. Branch Name: Specify your Azure DevOps source code branch which will be default source code sync location for the build VM. Default branch is "Main".
Click Done. And proceed with the deployment of VM.
When a Build VM is deployed, it is pre-configured and ready to start a build. It creates/updates the Main folder in Repos and creates a Pipeline in Devops.
First, you will find there a single pipeline named “Unified Operations platform – Build Main”. I would recommend keeping this pipeline as a template and creating your customized pipelines by cloning it. To edit the pipeline, see below, you can disable certain steps or add new steps.
Continuous Integration setup:
With the pipeline that was provisioned as part of VM deployment, we have the luxury of enabling continuous integration by editing the pipeline.
Check the option shown below to enable continuous integration. Right after every developer’s check-in to dev branch, a build will be queued, and the code compiled. In case there’s a compilation error we’ll be notified about it. Of course, we all build the solutions before checking them in.
A Gated check-in is that the build agent will launch an automated compilation BEFORE checking-in the code. If it fails, the changeset is not made until the errors are fixed and checked-in again.
You can also schedule the pipeline run along with CI whichever you see fit or even both.
Configure Release Pipelines:
We have released to tasks that will complete the CI/CD story. The first task is to upload the deployable package to the Asset Library in LCS and the second task is to apply the deployable package to any non-production environment. By now we all are aware that production environments will be managed by Microsoft and any deployable packages need to be marked as release candidate to be applied to production.
The first step to take is creating an app registration on Azure Active Directory to upload the generated deployable package to LCS. Go to Azure portal and once logged in go to Azure ActiveDirectory, then App Registrations and create a new app:
Next go to “Manage” and “API permissions” to add the Dynamics Lifecycle Services API. And select “user_impersonation” permission, then click on the “Grant permissions” button to apply the changes.
After setting it up, go to Azure devops -> Pipelines -> Releases and create a new release pipeline. Select “New release pipeline” and choose “Empty job” from the list.
Then you will see a Stage titles “Stage1” created. Click on save button at the top to save the pipeline.
On the Artifact box select the build which we will link to this release definition
Then click on Job1 and Add task to the Agent Job.
Search for Dynamics and select D365 Finance and Operations Tools and click “Get it Free”.
Then chose your Devops Team project for which these tools need to be installed.
After the installation is done, Refresh your browser and comeback to edit your Release pipeline, and edit the “Stage1” and add Task to “Agent Job 1”.
The first step in the task is setting up the link to LCS using the AAD app we created before. Press New and fill the fields. The Application ID is the Client ID of the App you created earlier in Azure portal.
It’s only necessary to fill in the connection name, username, password from the user and Application (Client) ID fields. The endpoint fields should be automatically filled in. Finally, press Save and the LCS connection is ready.
In the LCS Project Id field, use the ID from the LCS project URL, for example in https://lcs.dynamics.com/V2/ProjectOverview/1234567 the project is 1234567.
Press the button next to “File to upload” and select the deployable package file generated by the build:
If the build definition hasn’t been modified, the output Deployable Package will have a name like AXDeployableRuntime_VERSION_BUILDNUMBER.zip. Change the fixed Build Number for the DevOps variable $(Build.BuildNumber) like in the image below:
Then create an Output Variable to capture the package id and dynamically pass it to the next task.
Then proceed to the next Task “Deploy to Environment” to fill in the fields.
The Environment Name can be fetched from LCS.
The LCS Asset Id name will be the output variable from previous task: $(OutputVariableName.FileAssetId) . Once you are done filling the fields save and tasks and the pipeline.
One last thing to do before we complete continuous deployment is to enable that option through which this release pipeline runs whenever we have a successful build.
Congratulations you have successfully configured CI and CD for D365 F&SCM!!
*This post is locked for comments