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:
- https://freddysblog.com/category/ci-cd/
- https://www.linkedin.com/pulse/cicd-business-central-nav-using-azure-dev-ops-dennis-fredborg/
- https://github.com/olisterr/Webinars-Seminars/blob/master/365Saturday_Presentation_CICD_7-12-2019.pptx
- https://www.yammer.com/dynamicsnavdev/threads/414438668279808
- https://github.com/olisterr/CI-CD-
- https://aka.ms/cicdhol
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 |
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 |
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. |
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
Thank you for reading this! Hope this helps
Hi Olister,
ReplyDeleteVery good and informative article on CI/CD topic, do you have sample files on github for the article?
Mohamed
Hi Mohammed,
ReplyDeleteYou can refer here https://github.com/olisterr/CI-CD-
Hi Olister,
ReplyDeleteI 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.
Hi SD,
ReplyDeleteIt 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.
Hi Olister,
ReplyDeleteThanks 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