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!

C/AL and AL Side-by-Side Development with AdvaniaGIT

Microsoft supports Side-by-Side development for C/AL and AL.  To start using the Side-by-Side development make sure you have the latest version of AdvaniaGIT add-in for Visual Studio Code and update the PowerShell scripts by using the “Advania: Go!” command.

When the Business Central environment is built use the “Advania: Build C/AL Symbol References for AL” to enable the Side-by-Side development for this environment.  This function will reconfigure the service and execute the Generate Symbol References command for the environment.  From here on everything you change in C/AL on this environment will update the AL Symbol References.

So let’s try this out.

I converted my C/AL project to AL project with the steps described in my previous post.  Then selected to open Visual Studio Code in AL folder.

In my new Visual Studio Code window I selected to build an environment – the Docker Container.

When AdvaniaGIT builds a container it will install the AL Extension for Visual Studio Code from that Container.  We need to read the output of the environment build.  In this example I am asked to restart Visual Studio Code before reinstalling AL Language.  Note that if you are not asked to restart Visual Studio Code you don’t need to do that.

After restart I can see that the AL Language extension for Visual Studio Code is missing.

To fix this I execute the “Advania: Build NAV Environment” command again.  This time, since the Container is already running only the NAV license and the AL Extension will be updated.

Restart Visual Studio Code again and we are ready to go.

If we build new environment for our AL project we must update the environment settings in .vscode\launch.json.  This we can do with a built in AdvaniaGIT command.

We can verify the environment by executing “Advania: Check NAV Environment”.  Everything should be up and running at this time.

Since we will be using Side-by-Side development for C/AL and AL in this environment we need to enable that by executing “Advania: Build C/AL Symbol References for AL”.

This will take a few minutes to execute.

Don’t worry about the warning.  AdvaniaGIT takes care of restarting the service.  Let’s download AL Symbols and see what happens.

We can see that AL now recognizes the standard symbols but my custom one; “IS Soap Proxy Client Mgt.” is not recognized.  I will tell you more about this Codeunit in my next blog post.

I start FinSql to import the Codeunit “IS Soap Proxy Client Mgt.”

Import the FOB file

Close FinSql and execute the “AL: Download Symbols” again.  We can now see that AL recognizes my C/AL Codeunit.

Now I am good to go.