Monday, April 7, 2014

Easy Automated Builds - Part 1

I'm glad to announce updates to my Dynamics AX Admin Utilities, including a brand new build library. It's been in use here at Sikich for quite a while now, and with our latest modifications I'm glad to release the binaries (although as always the code is available at any time). I want to make sure to thank my partner in crime, Dan, for helping me out with the code and the testing it here internally. I also got some good feedback from a fellow MVP, Kenny Saelen, who's also implementing these activities and got me the final bits I needed to finally implement async. Thanks!
Now, these activities can be used with or without TFS. Yes, that's right. They are built against the TFS client libraries for optimal use with TFS. But I will show in an upcoming post that you can use these activities using regular .NET workflow as well.

The major difference with our previous activities is that these are 1) based on the work we've done around the admin utilities and 2) they are optimized for ease of use and minimal configuration of options. I will outline an example here using Team Foundation Server 2013 with AX 2012 R3. But note that we use the exact same libraries internally for AX 2012 RTM, AX 2012 FPK and AX 2012 R2 releases, using Team Foundation Server 2012. I'm fairly confident these activities will also work with TFS 2010 - however you may need to get the source and recompile the libraries against the TFS 2010 client DLLs. I will test this at some point. However, there is nothing special in the activities that is specific to TFS 2012 or 2013. I am pretty sure these activities will NOT work in TFS 2008 since a lot was changed in TFS going into 2010.

If you want to dive right in, download here. Reference documentation is here.


First, you'll need to download the binaries from CodePlex. The TFS release package includes all the needed DLLs (basically the dependencies on the admin utilities). There are no separate versions for AX RTM vs R2 vs R3, and no separate versions for TFS 2012 vs 2013 (the DLLs are built against TFS 2012 and work fine with the 2013 DLLs).
Once you have downloaded the zip file, you will need to put the DLLs in a project inside the TFS Project Collection where you will be doing builds. If you have multiple collections, you'll need to put the DLLs inside each one.


I chose to create a separate project called AXBuild and inside a folder called "Assemblies" I uploaded the activities. I doesn't matter where exactly you put them, as long as they are in the source tree somewhere.
Next, we need to go into the TFS Server Administration Console, open up the Build Configuration.


A few things to explain here. A build service is the process that accepts requests from clients to perform a build. A build controller orchestrates the builds and delegates the heavy lifting to a build agent. A build agent is the process that actually performs the build itself. An agent is registered with one controller only, the controller is tied to a service, the service is set on one specific project collection. You can run many services and controllers and agents, it's just important to note the roles they play. If you are just playing around and have only 1 thing to do with TFS and that's AX, you can stick with one collection, one service, one controller, and one agent :-)
Now, if you haven't installed a service/controller/agent yet, go ahead and run through the setup. If you have multiple agents (the default during install), you can run multiple builds at once. HOWEVER, keep in mind that each build will of course require its own AX AOS server! You don't want two builds running and trying to use the same instance of AX. Next, the agents should be installed on the AOS machine, so that the build process runs on the same server as the AOS. We may support remote builds at some point, but right now that's the way it goes - and it's really not an issue. In our setup we have a build service and controller running on the same machine as TFS itself. Then, we have specific build machines that just run one agent, connected to the main controller.

With that out of the way, the build controller is where we need to point to our custom activity assemblies. This of course means if you need these for multiple controllers, you'll have to set each one up to point to the assemblies. Also, make sure you log on to the machine with the build controller - in case you run the agent on a different machine. On the controller, click the Properties link. On the dialog that appears, you can set the path to your custom assemblies. You can look up the correct path by clicking the ellipsis button there.


Click OK and that is all we need to do here. We're now all setup and ready to create a build workflow. TFS has workflows that handle everything that is needed in a build. It creates a source label (if you don't know what that is, no problem), it grabs all the code, associates the work items from the changesets to the build, etc. And of course, it runs the compile. Now, the default workflows that come with TFS of course assume that you will be compiling a Visual Studio project. So, we want to take one of these pre-built workflows, remove the visual studio compile stuff, and add in whatever activities you wish to use to build AX.
Now, if you are using TFS 2013 (or Visual Studio Online), this is a WHOLE lot easier.

To edit the workflow, we will be opening a .NET workflow for TFS inside Visual Studio, and drag&drop our activities and set the properties. For this to work, Visual Studio needs access to the DLLs for the activities, of course. There are two ways to do this. You can just put the DLL files in the PublicAssemblies folder of Visual Studio ( in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies - replace your Visual Studio version with 10.0 for VS2010, 11.0 for VS2012 and 12.0 for VS2013). The other option is to actually create a VS project (let's say a C# class library), add the DLLs as a reference, and open the workflow in the context of this project. I personally find it easier to copy the DLLs in the public assemblies folder, but that's my choice.

We are now ready to create a workflow, which will be Part 2.

6 comments:

  1. That is a super writeup; I can't wait to start using it! Thank you very much!

    ReplyDelete
  2. Good job Joris, thanks for sharing ;)

    ReplyDelete
  3. Hi Joris. I am reading the MS best practice whitepaper "Change management and TFS integration for multi-developer projects" and there is a link to their scripts
    http://gallery.technet.microsoft.com/scriptcenter/Build-and-deploy-for-b166c6e4

    I just wonder if know on a high level what are the difference between your scripts and the ones Microsoft has released. My impression is that in your case the scripts are more advanced (which makes them probably also more complex).

    I am quite new to automated builds with TFS and wonder if we really need the full package of feature.
    We have just a few developers in house (end user) and I assume we just need the basic scenario.

    What do you think?

    Thanks, Waldemar

    ReplyDelete
    Replies
    1. They are more complex as far as capabilities, but they are definitely easy to use if you only need the basics.
      Microsoft's scripts, last I checked, had issues with the modelstore after it was changed in R2, but I hope they've updated that since. The issue with those is that you'll need to modify powershell scripts if you need to make changes.
      The activities I have are drag&drop into a .NET workflow. You can go as simple as just dragging a compile step into workflow, give it a configuration file to an environment, and off you go (of course this wouldn't pull code in). You can go as far as we're using it - where we have central build machines that build code for any of our clients and produce versioned models and run unit tests.
      Each activity can be dragged in, there's "AOS Start" and "AOS Stop" and compile, CIL, synchronize etc. You can drag&drop into the workflow with the steps you need.

      Delete
    2. Thank you for the explanation! Will check them out.

      Delete