Skip to main content

CI/CD in NAV / Business Central Development using Azure DevOps

Introduction:

Azure DevOps is a very handy tool to manage project tasks, milestones, bugs, and documentation.
But it is not just limited to that, it can also be used to manage all your deployments and building pipelines to manage your deployments.
Lets take a look how to do this and how we can setup our repository to make auto deployments.

Pre-requisites:

  • VS Code
  • Microsoft Dynamics NAV / Business Central
  • Azure DevOps Subscription
  • Understanding of  Version Source Control System like Github or TFS
  • Understanding of PowerShell

Books & References:

Demonstration:

1. Creation of Azure DevOps Repository: Creation of Azure DevOps Repository is the starting point of the every code related activities in any projects. Azure DevOps Repository is one of the source control application from multiple application  such as TFS(VSTS) and GitHub.
Importing a Git Repository from AL Ops Template
Repository Created in Azure DevOps

2. Cloning Repository in VS Code:
After creating repository in Azure DevOps, the project is to be cloned to local project in the PC. Thus, after the cloning is done, you can create your project files which can then be synced to remote repository created on Azure DevOps.
Creation of Local Repository in VS Code

3. Creation of PowerShell script for auto compilation and deployment:
i. Copying the Compiler from VS Code existing extension compiler:
In order to compile the Business Central Project on the Windows machine, you require a compiler. Now, if the deployment has to happen automatically on random machine auto-created by Azure Pipelines, you also need to copy the Compiler from your Local Machine to your Remote Project folder. From there there the Compiler can be referenced and used to compile on the Remote Machine created.  

By Default the ALC (AL Compiler) is stored on path
C:\Users\<USERNAME>\.vscode\extensions\ms-dynamics-smb.al-<VERSION>\bin
In this case, I have copied this to the project folder like this

ii. Creating PowerShell to Compile the project based upon the objects created and  Symbols: Using the ALC, you can now compile the Project and Symbols as parameters.
The syntax for the project to compile is :
<Path to ALC>  /project:<PROJECT FOLDER PATH>  /out:<APP OUTPUT PATH> /packagecachepath:<PROJECT FOLDER PATH>\.AlPackages


AL Compile Syntax
iii. Creating PowerShell command to deploy the App File created to  Business Central using APIs: Whenever you hit Ctrl + F5 in VS Code, the VS Code actually calls the APIs in a PUT method to with the parameter as the .App File created after the compilation of the Business Central Project. Well even I'm going to do the same thing.
In terms of Authentication, I will be calling my APIs using Basic authentication which is Username and Webservice key defined in Users Page. Overall, I did it with the help of PowerShell below.
Deploy Business Central App using PowerShell

Thank you @FreddyK(https://twitter.com/freddydk) for providing me the reference material to call the Business Central APIs for App Development (http://aka.ms/cicdhol)

4. Creation of Azure Pipelines YAML: After all this has been set, now it is time to automate the procedure. Basically, I want the system to work as whenever I Commit and Push my code into Azure DevOps Repository, The Azure Pipelines will pickup from the Commit, Compile the project and Deploy it to Business Central using the PowerShell Script called above.
These auto deployments are done with the help of YAML files below.  
YAML File to automate the deployments
YAML files consists of set of Tasks, Scripts and Configurations used by Azure Pipelines to spin-up a temporary Virtual Machines and Run all the Codes configured in the YAML files.

5. Output:
Whenever I commited my code to Azure DevOps, a following screen is seen.
Code Commits with Azure Pipelines Status

A command line window appears showing the processing of the PowerShell Script called through the YAML Task.
Execution of Azure Pipelines and PowerShell Task.
Finally, after the code is deployed to Business Central you will get the following Output.
Business Central Output after the code is deployed!

Conclusion:
As you can see you can use this process for each of the code commits that happen ensuring that the code is deployed correctly. This can also be configured for each of the branch of repository and every developer can auto deploy it to their specific tenants.

Also, ALOps is one of the best tool to automate your Business Central deployments. Blog on that topic will follow soon.

Thank you for reading this! Hope this helps

Comments

  1. Hi Olister,

    Very good and informative article on CI/CD topic, do you have sample files on github for the article?

    Mohamed

    ReplyDelete
  2. Hi Mohammed,
    You can refer here https://github.com/olisterr/CI-CD-

    ReplyDelete
  3. Hi Olister,

    I am trying to replicate the same scenario but getting error while try to compile the app

    Getting error

    Version : 2.165.0
    Author : Microsoft Corporation
    Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
    ==============================================================================
    Generating script.
    Formatted command: . 'd:\a\1\s\CICDProject\Compile-PS.ps1'
    ========================== Starting Command Output ===========================
    "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\ed8ad533-b3c9-431f-8cb9-875c25e6cf13.ps1'"
    .\CICDProject\ALCompiler\alc.exe/project:.\CICDProject/out:.\CICDProject\NAGCICD.app/packagecachepath:.\AlPackages :
    The term
    '.\CICDProject\ALCompiler\alc.exe/project:.\CICDProject/out:.\CICDProject\NAGCICD.app/packagecachepath:.\AlPackages'
    is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
    or if a path was included, verify that the path is correct and try again.
    At D:\a\1\s\CICDProject\Compile-PS.ps1:3 char:1
    + .\CICDProject\ALCompiler\alc.exe/project:.\CICDProject/out:.\CICDProj ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (.\CICDProject\A...th:.\AlPackages:String) [], ParentContainsErrorRecord
    Exception
    + FullyQualifiedErrorId : CommandNotFoundException

    ##[error]PowerShell exited with code '1'.
    Finishing: Compile the App

    Could you please suggest how to write the command in Compile.ps1.

    ReplyDelete
  4. Hi SD,

    It looks like you command is not pointing correctly to ALC and its parameters.

    I would recommend that you use everything in the same project folder.
    Also I noticed that there are no spaces to seperate ALC and its parameters.

    Generally you 'cd' into ProjectFolder then you call .\ALCompiler\alc.exe and then the project path is ./ and output path is ./OutputFile.app

    Refer http://dankinsella.blog/business-central-al-compiler/


    I hope this helps.

    ReplyDelete
  5. Hi Olister,
    Thanks for the reply but still i m not able to write the command successfully,
    My command is "Set-location C:\NAGRepo\NAGCICD\CICDProject\ALCompiler > alc.exe /project:C:\NAGRepo\NAGCICD\CICDProject /out:C:\NAGRepo\NAGCICD\CICDProject\NAGCICD.app /packagecachepath:C:\NAGRepo\NAGCICD\CICDProject\ALPackages"

    Does the above command work on the Azure?

    I am still getting error in the Azure Pipeline

    Starting: Compile the App
    ==============================================================================
    Task : PowerShell
    Description : Run a PowerShell script on Linux, macOS, or Windows
    Version : 2.165.0
    Author : Microsoft Corporation
    Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
    ==============================================================================
    Generating script.
    Formatted command: . 'd:\a\1\s\CICDProject\Compile-PS.ps1'
    ========================== Starting Command Output ===========================
    "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\3b8ca8d4-6ed2-401a-8a5b-0c10b258841a.ps1'"
    Set-Location : Cannot find path 'C:\NAGRepo\NAGCICD\CICDProject\ALCompiler' because it does not exist.
    At D:\a\1\s\CICDProject\Compile-PS.ps1:5 char:1
    + Set-Location C:\NAGRepo\NAGCICD\CICDProject\ALCompiler
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (C:\NAGRepo\NAGC...ject\ALCompiler:String) [Set-Location], ItemNotFoundE
    xception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

    ##[error]PowerShell exited with code '1'.
    Finishing: Compile the App

    Could you help me to rectify the above.

    Thanks

    ReplyDelete

Post a Comment

Let me know your comments below. I'll try my best to answer your comment

Popular posts from this blog

Something went wrong. An Error occurred - Error Resolution

Introduction: With the installation of NAV 2018 or BC On-premise, I have observed that when creating New Server Instance and New WebServer Instance, you will get the error 'Something went wrong. An Error occurred '. I referred to the community questions below but didn't find my resolution. Hence, I decided to write this blog. Pre-requisites: Microsoft Dynamics Business Central - On-Premise / NAV 2018 Understanding of Business Central Authentication  Books & References: https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/261301/nav-2018-web-client-an-error-has-occurred https://community.dynamics.com/business/f/dynamics-365-business-central-forum/421987/error-something-went-wrong-an-error-has-occurred-azure-ad-tenant Demonstration: 1. Creation of NAVServerInstance: In order to create NAVServerInstance, you can either add the Server Instance through Business Central Administration or Powershell command. Add Instance - Business Central Administration Add Insta...

How to resolve 'Edit in Excel' issues

  Introduction: As you know that D365 BC offers Edit in Excel functionality. But manipulating or customizing such a  standard functionality is difficult as there is not much control available. Hence, solving issues is also a difficult task. I will be resolving the issue for this specific issue, however, the debugging steps are similar. Pre- requisites : ODATA V4 Connectivity tool for Webservices Microsoft Dynamics 365 Business Central Books & References: https://community.dynamics.com/business/f/dynamics-365-business-central-forum/448226/issue-with-excel-add-in/ Demonstration: The way Edit in Excel works is that for a given page a Webservice is created adding PageID and Page Name. Hence, there are some Webservice connectivity checks in place to validate. 1. Edit in Excel Custom Action on the page: If you are adding Edit in Excel Action on the page, please ensure that you are providing appropriate PageName and Filter criteria as Webservice is using these parameters Refer Ed...

Installing LS Central - POS on local machine

Introduction: In this blog, I'm attempting to capture the LS Central - POS installation process on Local Machine. This blog has nothing to do LS Central - Server Setup for POS. LS Retail / LS Central - On Premise POS Pre- requisites : LS Central Installed on Server SSL Setup on LS Server (https://www.olisterr.tech/2020/03/how-to-setup-navuserpassword-with-ssl.html) LS - POS Installer Business Central - On Premise Installer Demonstration: Once your LS Retail / LS Central POS is setup on the main server. Just prior to Go-Live, you will actually have to install this POS on multiple systems and connect these POS to the main server with LS Retail / LS Central. 0.Preparation: Prior to actually installing Business Central On-Premise Windows Client, you need to make sure that you're able to ping the target with the correct Port number. For this I made use of PS-Ping tool.  PSPing - IP Address: Port If you're unable to PS-Ping the correct IP with Port number, simply check the Advan...