Kine's Info

What I found and what I know about Microsoft Dynamics NAV

Automatic builds of Microsoft Dynamics NAV

Are you dreaming about possibility to automatically “build” your NAV database after you commit changes to the objects to check if all could be compiled and to be able to run the automated tests? It could become reality for you!

 

Of course, you have many paths, but I will talk about the way, I have prepared using the PowerShell scripts + TFS Build server. After I have developed the template andscripts, I was informed, that something similar could be done using the FAKE (http://fsharp.github.io/FAKE/). But, who wants to learn F# when I just started to learn Powershell? Mrkající veselý obličej

 

How it works

Whole build is using separate powershell scripts for these steps:

  1. Create the SQL database with base objects, create NAV server for this database
  2. Import txt files with objects, which differs from the base objects
  3. Compile the objects (all or only updated from step 2)
  4. Run test codeunit and process the results (not done yet)
  5. Export the objects as FOB file (result of the build)
  6. Drop the NAV server and SQL Database (clean up, could be disabled)

If you need to change something in this, you can only change the PS script and you are done. You do not need to change the Build template. And because you can do different things in the PS, you can unleash your imagination…

What you need

  1. one TFS 2013 Build server
  2. one MS SQL Server
  3. one NAV 2013 R2 installation
  4. TFSBuildTemplate folder from the navscripts.codeplex.com in your TFS GIT repository
  5. Visual Studio
  6. one Windows server
  7. copy of content from Scripts folder of the navscripts files in c:\Program Files\WindowsPowerShell\Modules\ folder of the Build server
  8. some GIT repository with txt files for each NAV object (placed in folder Objects in the repos, see Issue #4 on codeplex project)

Mix it all, install on some HW (virtual or real), configure TFS for the TFS Build.

 

How to use it

  1. Open visual studio, connect to your TFS project (GIT repository must be used in the tfs project), open Builds in the Team Explorer.
  2. Select Actions-Manage Build Controllers
  3. Select the build controller, click Properties
  4. Set the Version control path to custom assemblies. It should lead to the TFSBuildTemplate\Custom Assemblies\ folder from the navscripts project somewhere on your GIT repo
  5. Close the controller dialog
  6. Click New Build Definition in Visual Studio.
  7. Name the build, do not use spaces or other special characters. They are doing problems in the powershell scripts when running finsql.exe to import/compile/export objects
  8. Set the trigger as you wish
  9. Seth the Source to the repository with the NAV objects, select branch to build
  10. In Build Defaults select if you want to copy the output (the resulting FOB file) to be copied to some drop folder
  11. In Process tab click “Show details” in the Build process template section
  12. Click New
  13. Select the project, repository, branch and path where the GitTemplateNAV.12.xaml from the navscripts project is placed
  14. Be sure, that the template is selected
  15. Set the NAV DB Backup file to some SQL backup file (must be accessible from the build machine, for the build account). It could be e.g. NAV cronus database backup file or some backup of your database.
  16. Set the Update FOB File to some FOB file, which will update the backup restored from previous point to objects, which could be updated by importing txt files. It could be e.g. file with the rollup update. If you set the Import FOB from last build (and the NAV Build Drop Folder will be set to the Drop folder of the build), instead the firmly set FOB file the latest FOB found in the folder will be used.
  17. Set the License File to some flf file. This will be used for the build process. The license must have enough permissions to import the txt files.
  18. Set the NAV Ide path – this path will be used to run the NAV Dev env.
  19. You can set the ID of the codeunit which runs the tests. It will be invoked after the objects are compiled
  20. If you want to shorten the build time and you do not need to compile all objects to check if all is ok, you can set Compile only not compiled. Process will then build only objects which are not compiled in one go.
  21. If you want to leave the SQL DB and NAV Server after the build available, set the Drop NAV Server and DB at the end to True. You can use this DB an NAV Server as Last Build server.
  22. Set the SQL Server name, SQL database name and NAV Server instance name to what you want.
  23. Save the build definition
  24. Queue the build

After you queue the build, it should be processed by the Build controller, assigned to the Build agent and started. You should monitor the process of the build to see if there are some problems. I assume that few builds will fail until you finish all needed settings, finetune some paths etc. If all goes well, in the Drop folder will be created folder with the Build definition name, and there will be FOB file in it.

 

Customizations

If you want to customize some step, you can do two things:

  1. Change the powershell scripts used by the build
  2. Change the Build template

If you want to change the build template, you can do that by opening the solution from the TFSBuildTemplate. Because the template is using custom actions from the https://tfsbuildextensions.codeplex.com/, follow their documentation how to set the Visual Studio to be able to use the extensions if there is some problem. After you commit the change of the template, the change will be automatically used by the build definitions.

 

I wish you happy NAV building!

 

Feedback is welcome! You can use the codeplex project issue tracking to share the problems, issues, feature requests…



  • Hi Kine,

    Know you posted this a long time ago. In terms of NAV, this is a long time ago. NAV 2016 offers most of the features to export objects out of the box. But how does this effect creating builds using TFS in 2016?

  • Hi Erik, sorry for late respone, but have not seen the comment...

    This post is really old, I was using XAML build definitions for TFS and some custom library to run PowerShell in the build. With TFS 2015 you have new Build agent with native PowerShell support, thus it is much easier to do all what is needed. Just look at the new articles I wrote... dynamicsuser.net/.../tfs-2015-build-system