Setting Up Continuous Integrations in Dynamics 365 for Operations

By Mark Nelson | September 26, 2017

Previously I showed you how to set up version control in Dynamics 365 for Operations. Now we will look at setting up a continuous integration build for our project.

Let’s say we need to write a method that sorts an array of ItemId values. The method should sort the array in place so we can simply pass in our array and it will be sorted afterward. We’ll start by creating new projects and models called ContinuousIntegration and ContinuousIntegration Test. These projects will consist of a single class each. The first contains a simple method that performs a bubble sort on an array of ItemIds. The second contains a unit test class.

The new projects and models created called ContinuousIntegration and ContinuousIntegration Test, and these projects will consist of a single class each.

Once we verify that the code works as expected and our unit tests all pass, we can submit it to our code repository.

Create a Build agent

Now we need to set up a build agent using the SetupBuildAgent.ps1 PowerShell script found in the C:\DynamicsSDK folder. This script requires us to authenticate to VisualStudio.com using something called a Personal access token. This token is a string of characters that replace your username and password when authenticating to the site.

In my testing, I have found that the build agent must use a Personal access token created by the administrative account for your project. If you later add a user to your project, even if that user has admin privileges for that project, you cannot use an access token from that user.

To create your Personal access token, navigate to VisualStudio.com, log in, click your user icon in the top-right corner, and choose Security.

To create your Personal access token, navigate to VisualStudio.com, log in, click your user icon in the top-right corner, and choose Security.

Click the Add button to create a new Personal access token and give it a name.

Click the Add button to create a new Personal access token and give it a name.

Scroll to the bottom of the page and click Create Token. You must now copy your token value and store it in a safe place until you are done setting up your continuous integration server. This token will only be displayed to you once. When you leave this page you will no longer be able to see its value.

(This is not my actual token.)

The token will only be displayed once so it's important to copy it now or you won't be able to see it again.

On your build VM, open an administrative command prompt and change to the C:\DynamicsSDK directory.

Now we need to call the SetupBuildAgent.ps1 script and pass it the values it needs to connect to our project. At a minimum we need to provide the following parameters:

My command line would look something like this:

Command line

When you press enter, the script will download the latest version of the build agent as a Zip file, extract it to a VSOAgent folder, and create a Windows Service instance.

The script downloaded the latest version of the build agent as a Zip file, extract it to a VSOAgent folder, and create a Windows Service instance.

We can see the Build agent online if we navigate to our dashboard, click the settings button, and choose Agent pools.

View the build agent online.

View and download the build agent online.

If we load the services control panel on our build VM we can see the new Windows service tied to this agent.

Load the services control panel on our build VM we can see the new Windows service tied to this agent.

Create a Build Definition

The last step is to create a build definition. The build definition defines what steps will be taken when our continuous integration build runs and even defines when our build will run.

To create the build definition, we will use the BuildEnvironmentReadiness.ps1 PowerShell script.

To create the build definition, we will use the BuildEnvironmentReadiness.ps1 PowerShell script.

When you press enter the script will create the build definition.

Create the build definition.

To see the definition, navigate to your project home and click Build and Release > Builds.

To see the definition, navigate to your project home and click Build and Release > Builds.

To see the definition, navigate to your project home and click Build and Release > Builds.

Click the build definition name to see the details.

Click the build definition name to see the details.

Then click the Edit button to see the build steps.

Then click the Edit button to see the build steps.

To enable Continuous integrations, click the Triggers tab, enable the option, and click Save.

To enable Continuous integrations, click the Triggers tab, enable the option, and click Save.

Submitting code changes

Now that we have continuous integrations enabled, every time we submit a change our code will be built and tested. To test this, let’s assume that our requirements have changed and we now must use a quick sort to sort our ItemIds.

Let's submit a change to our code so we now must use a quick sort to sort our ItemIds.

If we refresh our build definitions page, we can see that our continuous integration build has been triggered by our change.

You can see that the continuous integration build has been triggered by the change.

If all goes well the build will be successful, tests will pass, and we can be assured that our branch is stable.

If all worked correctly the build will be successful, tests will pass, and we can be assured that our branch is stable.


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!