25 Jun 2017 | ALM | Visual Studio Team Services | Dynamics CRM | Dynamics CRM Online | Git
In previous posts I've setup build and release defintions for Dynamics CRM solutions and in this one I try my attempt at setting up an automated Continuous Delivery pipeline. There are two popular strategies used to make sure that every change made to a system can be deployed successfully to secondary environment:
Continuous Integration (CI)
A CI build is one that is usually kicked off any time a piece of code is checked-in in order to give early visibility of any potential failures. The success of a build is dependent on the actual build plus any unit tests.
Scheduled
A scheduled build, also commonly referred to as a Nightly Build
, is a build and release that is performed on a regular cadence - usually every night. Once again, on the successful completion of the build and automated unit test, a new release is pushed to the staging environment.
Both methods appear to be doing the same thing, so when should I choose a CI build + release over a scheduled build? The most common metric appears to be the duration of your build and unit tests. The size of the team, the project and code complexity and the frequency of check-ins can have an impact on the time it takes for build and long running unit tests to execute. In these scenarios a Scheduled
build makes more sense.
I was disappointed to find out that, at the time of writing this post, VSTS release definitions does not provide an option to trigger off a successful a scheduled build. The only options available are to trigger it off of a CI build or the automated schedule on the release itself.
Luckily, Rene van Osnabrugge's excellent post provides us with a workaround for this restriction. Here's an overview how it works:
Lets get started setting it up.
As in my previous posts I will be using a standard Dynamics CRM build for this demonstration. Follow the instructions in my previous post for setting this up .
Now let's make the following modifications:
Triggers
tab.Batch changes while a build is in progress
check box. add
button.Exclude
and Path specification
to /Nullfactory.Xrm.Tooling
. We don't really care for our tools to This is so that we only trigger on the actual solution and not the supporting tools/project.Next, we update the build to tag itself upon a successful build.
Nullfactory.Xrm.Tooling/Scripts
project folder.Add Task
button and select a PowerShell task. I placed it as the last step in the order.Configure it with the following values:
Tag Build Reason
File Path
Nullfactory.Xrm.Tooling/Scripts/Set-BuildTagToTrigger.ps1
-BuildId $(Build.BuildId)
Ensure that the task only runs if all previous tasks have succeeded. Do this by navigating into Control Options
section and selecting the option within the Run this task
drop down.
In order for the the script to have authenticated access to the REST service it requires access to the OAuth token. Do this now navigating to the Options
tab and enabling the Allow scripts to access OAuth token
.
Queue a new build and verify that a tag was associated with the build. Note that since we invoked the build explicitly, a manual
tag was added.
The tags applied to the new build are the same values as the build reason environmental variable. We only care about the following scenarios:
Manual
IndividualCI
BatchedCI
Schedule
In fact, we only care about the Schedule
typed of builds. Find the full list of available values here.
Now that the build is complete and we've proven that the solution is good enough to be deployed, let's create and augment our release definition.
Follow the steps described here to create the basic release definition. Ensure that the linked source is the build definition we created earlier.
Triggers
menu.Continuous Deployment
check box.schedule
as the tag filter.Save
to confirm changes.Verify that the when the build is triggered via the schedule and that it has a schedule
tag is associated upon completion.
Verify that a release was deployed off of it.