AdvaniaGIT: Configure Build and Test using Visual Studio Online

The goal of this post is to demo from start to finish the automated build and test of an AL solution for Microsoft Dynamics 365 Business Central.

Configure build steps

The build steps using AdvaniaGIT are similar to the build step Soren describes here.

The first two steps and the last one is automatically created.  We create PowerShell steps to be executed in between.

To begin with I like to make sure that the previous build environment is removed.  If everything is configured and working correctly the environment is removed in the end of every build.

Since I am working on daily builds I like to leave the environment active after the build so that I can access the latest environment any time to look at code and configuration changes.

When putting together this build I used some of the information found on Tobias Fenster blog and also from Kamil Sacek blog.

Remove existing container

Every PowerShell  task executes the basic command with different parameters.  The script path is

The Arguments are defined for each task.  I always select which script to execute and always add the ‘BuildMode=$true’ settings.

Remember that the ‘setup.json’ configuration and the machine configuration in the read as every action is started.

the ‘setup.json’ parameter ‘projectName’ is used as the docker container name.  This first action will look for a container matching the ‘projectName’ and remove it.

Build and Update Docker Container

This task will start download the docker image that is defined in the ‘dockerImage’ property in ‘setup.json’. 

To make sure that docker allocates enough memory for the build use the ‘dockerMemoryLimit’ parameter and allow at least 4G of memory.

The ‘dockerTestToolkit’ parameter is required if the AL Test application uses the standard test toolkit libraries.  The G/L Source Names test application uses some of the standard libraries and therefore, using this parameter, I trigger the toolkit import into my docker container.

Initialize Test Company

The daily builds are not shipped with the CRONUS company.  To be able to execute the test using the NAV Client I need to have a company marked for evaluation.

This action will remove the existing company, create a new evaluation company and run the Company Initialize Codeunit.

If you are not running tests then this step is not needed.

Download AL Add-in

The build machine will create a folder in ‘C:\AdvaniaGIT\Workspace’ using the ‘branchId’ from ‘setup.json’.  That said, we can only have one build process running for each GIT branch.  I have not found the need to allow multiple concurrent builds for a GIT branch.  

The AL extension for VS Code is downloaded and extracted to the ‘vsix’ folder.

Download AL Symbols

The symbol files (app files) are required to build the AL application.  These two files are downloaded from the docker container into our work space ‘Symbols’ folder.

Build AL Solution

The AL app will be compiled and created in the work space ‘out’ folder.  I add the ‘Build.BuildID’ from Visual Studio to my app version in every build.  Remember that the AL solution is in the AL folder on my GIT branch as stated in the machine configuration.  Overwrite that configuration in ‘setup.json’ or with ‘BuildSettings’ parameter if needed.

Copy AL Solution to Symbols

The ‘APP’ file is copied from the work space ‘out’ folder to the work space ‘Symbols’ folder.  This is required since I am building the test app on top of the solution app.  If you are not running tests the you can skip this and the next five tasks.

Build AL Test Solution

This task is almost identical to the AL solution build task.  Here the machine parameters for the AL solution and the Test solution are combined into a single folder ‘ALTests’ to locate the folder containing the AL test application source code.

The test application ‘APP’ file is copied to the work space ‘out’ folder.

Install AL Extension

All the ‘APP’ files from the work space ‘out’ folder are published and installed in the docker container.

Execute AL Test Codeunits

This task requires the ‘idRange’ in the ‘app.json’ to be specified.

Every Codeunit in this number range with ‘subtype=upgrade’ will be added to the test pipeline.

The server instance is restarted before the tests are executed.  I have asked Microsoft to do one code change to be able to skip this step.

The tests are then executed using the NAV Client that is copied to the build machine and started from there.

Save Test Results

Test results are downloaded from the docker container database and formatted into the VSTest Xml format.  The ‘TestResultPath’ is a sub folder of the repository path.

Publish Test Results

This task is a built-in Visual Studio task.  The test result files must match the ‘TestResultPath’ in the previous step.

The ‘$(System.DefaultWorkingDirectory)’ is the repository path.

Copy AL Solution to Artifact folder

The ‘Artifact’ folder is created in the repository folder and every ‘APP’ in the work space ‘out’ folder is copied to this folder.

Sign AL Solution in Artifact folder

The code signing certificate is needed and must be available on the build machine.  The ‘signtool.exe’ to be used, the certificate path and the certificate password are specified in the machine setup ‘GITSettings.json’.

Publish Artifact: App

This is also a Visual Studio task that will upload all files in the ‘Artifact’ sub folder in the GIT repository to the build artifacts.

Remove Container

In my setup I disable this and the next task.  This is done so that I can work with the results and the development environment after the build.  This task is also configured to be executed even if something fails in the build pipeline.

Remove Branch Work Folder

The folder created in the work space by adding the branch ID will take up space on the build machine.  This task will remove that folder and everything it contains.

Delete Logs

When AdvaniaGIT executes custom actions a log folder is created.  The log folders are located in ‘C:\AdvaniaGIT\Log’ folder.

When the NAV Client is copied to then host it is stored in a log folder.

Every sub folder that is older than seven days will be removed from the log folder in this task.

Conclusion

I configured my build machine as described in my previous post.

I use my free subscription to Visual Studio Online to store my source code in GIT.

I installed the build agent on my build server and connected to my Visual Studio Online subscription.

I added the docker repository information and login credentials to the ‘DockerSettings.json’ to be able to build the daily builds.

AdvaniaGIT is accessible on GitHub.

Good luck!

AdvaniaGIT: About the build steps

The goal of this post is to demo from start to finish the automated build and test of an AL solution for Microsoft Dynamics 365 Business Central.

About the build steps

All build steps are execute in the same way.  In the folder ‘C:\AdvaniaGIT\Scripts’ the script ‘Start-CustomAction.ps1’ is executed with parameters.

The AdvaniaGIT custom action is executed in the same way from a build machine and from a development machine.

When we created the container in our last post from Visual Studio Code with the command (Ctrl+Shift+P) ‘Build NAV Environment’, Visual Studio Code executed

From the build task we execute ‘C:\AdvaniaGIT\Scripts\Start-CustomAction.ps1’ with these parameters

We can see that these commands are almost the same.  We have the one additional parameter in the build script to notify the scripts that we are in Build Mode.

Each AdvaniaGIT build or development machine has a ‘C:\AdvaniaGIT\Data\GITSettings.Json’ configuration file.

When the scripts are started this file is read and all the settings imported.  Then the repository setup file is imported.  The default repository setup file is ‘setup.json’ as stated in GIT settings.  If the same parameters are in both the machine settings and in the repository settings then the repository settings are used.

The same structure is used for the ‘BuildSettings’ parameter that can be passed to the custom action.  The build settings will overwrite the same parameter in both the machine settings and the repository settings.

The default settings are built around the folder structure that I like to use.  For example, we have our C/AL objects in the ‘Objects’ folder.  Microsoft has their objects in then ‘BaseApp’ folder.  Just by adding the ‘objectsPath’ parameter to the repository settings for the Microsoft repository I can use their structure without problems.

If I wan’t to execute the same exact functionality in Visual Studio Code as I expect to get from my build script I can add the ‘BuildSettings’ parameter to the command.

The folder structure

The structure is defined in settings files.  By default I have the ‘AL’ folder for the main project and the ‘ALTests’ folder for the test project.  Example can be seen in the G/L Source Names repository.

In C/AL we are using deltas and using the build server to merge our solutions to a single solution.  Therefore we have a single repository for a single NAV version and put our solutions and customization into branches.

In AL this is no longer needed.  We can have a dedicated repository for each solution if we like to, since the scripts will not be doing any merge between branches.

AdvaniaGIT: Setup and configure the build machine

The goal of this post is to demo from start to finish the automated build and test of an AL solution for Microsoft Dynamics 365 Business Central.

Setup and configure the build machine

We will create our build machine from a standard Windows 2016 template in Azure.

Docker containers and container images will take a lot of disk space.  The data are stored in %ProgramData%\docker

It if obvious that we will not be able to store the lot on the system SSD system drive.  To solve this I create an 1TB HDD disk in Azure.

After starting the Azure VM and opening the Server Manager to look at the File and Storage Service we can see the new empty disk that need configuration.

Right click the new drive to create a new volume.

And assign the drive letter

Next go to Add roles and features to add the Containers feature.  More information can be found here.  We also need to add ‘.NET Framework 3.5 Features’.

I also like to make sure that all Microsoft updates have been installed.

Now I start PowerShell ISE as Administrator.

As Windows Servers are usually configured in a way that prohibits downloads I like to continue the installation task in PowerShell.

To enable all the scripts to be executes we need to change the execution policy for PowerShell scripts.  Executing

will take care of that. 

Confirm with Yes to all.

To make sure that all the following download functions will execute successfully we need to change the TLS configuration with another PowerShell command.

Let’s download Visual Studio Code!  Use the following PowerShell command

to download the installation file to your desktop.  Start the installation.  During installation I like to select all available additional tasks.

We also need to download GIT.  Using the following PowerShell command

will download the latest version at the time of this blog post.  The only thing I change from default during GIT setup is the default editor.  I like to use Visual Studio Code.

Go ahead and start Visual Studio Code as Administrator.

Add the AdvaniaGIT extension to Visual Studio Code

Install AdvaniaGIT PowerShell Scripts!  We access the commands in Visual Studio Code by pressing Ctrl+Shift+P.  From there we type to search for the command ‘Advania: Go!’ and the when selected we press enter.

You will get a small notification dialog asking you to switch to the AdvaniaGIT terminal window.

Accept the default path for the installation but select No to the two optional installation options.

We need a development license to work with NAV and Business Central.  This license you copy into the ‘C:\AdvaniaGIT\License’ folder.  In the ‘GITSettings.json’ file that Visual Studio Code opened during AdvaniaGIT installation we need to point to this license file.

The DockerSettings.json file is also opened during installation and if you have access to the insider builds we need to update that file.

If not make sure to have all setting blank

Save both these configuration files and restart Visual Studio Code.  This restart is required to make sure Visual Studio Code recognizes the AdvaniaGIT PowerShell modules.

Let’s open our first GIT repository.  We start by opening the NAV 2018 repository.  Repositories must have the setup.json file in the root folder to support the AdvaniaGIT functionality.

I need some installation files from the NAV 2018 DVD and I will start by cloning my GitHub NAV 2018 respository.  From GitHub I copy the Url to the repository.  In Visual Studio Code I open the commands with Ctrl+Shift+P and execute the command ‘Git: Clone’.

I selected the default folder for the local copy and accepted to open the repository folder.  Again with Ctrl+Shift+P I start the NAV Installation.

The download will start.  The country version we are downloading does not matter at this point.  Every country has the same installation files that we require.

This will download NAV and start the installation.  I will just cancel the installation and manually install just what I need.

  • Microsoft SQL Server\sqlncli64
  • Microsoft SQL Server Management Objects\SQLSysClrTypes
  • Microsoft Visual C++ 2013\vcredist_x64
  • Microsoft Visual C++ 2013\vcredist_x86
  • Microsoft Visual C++ 2017\vcredist_x64
  • Microsoft Visual Studio 2010 Tools For Office Redist\vstor_redist

To enable the windows authentication for the build containers we need to save the windows credentials.  I am running as user “navlightadmin”.  I securely save the password for this user by starting a command (Ctrl+Shift+P) and select to save container credentials.

For all the docker container support I like to use the NAV Container Helper from Microsoft.  With another command (Ctrl+Shift+P) I install the container helper to the server.

To complete the docker installation I execute.

in Visual Studio Code Terminal.

We need to point docker to our data storage drive.  Kamil Sacek already pointed this out to us.

I use Visual Studio Code to update the docker configuration.  As pointed out here the default docker configuration file can be found at ‘C:\ProgramData\Docker\config\daemon.json’. If this file does not already exist, it can be created.  I update the ‘data-root’ configuration.

Now let’s restart the server by typing

or manually.

After restart, open Visual Studio Code as Administrator.

Now to verify the installation let’s clone my Business Central repository.  Start command (Ctrl+Shift+P) ‘Git: Clone’ and paste in the Url to the repository.

This repository has a setup.json that points to the Business Central Sandbox.

Make sure to have the Integrated Terminal visible and let’s verify the installation by executing a command (Ctrl+Shift+P) ‘Advania: Build NAV Environment’ to build the development environment.

The image download should start…

You should now be able to use the command (Ctrl+Shift+P) ‘Advania: Start Client’,  ‘Advania: Start Web Client’, ‘Advania: Start FinSql’ and ‘Advania: Start Debugger’ to verify all the required NAV/BC functionality.

If you are happy with the results you should be able to install the build agent as shown by Soren Klemmensen here.