Business Central Release Pipeline to Sandbox and Production Environments

Published on 27 August 2023 at 07:00

Introduction

In the previous post, we described how to create a build pipeline for a simple Microsoft Dynamics 365 Business Central application. In this post, we will demonstrate how artifacts from the build pipeline can be used for deployment to Sandbox and Production environments.

Prerequisites

  • Created build pipeline in this post

Script for publishing app

In your app create power shell script for publishing app

Source code:

#install bccontainerhelper
Write-Host "##[command]Installing BcContainerHelper"
Install-Module -Name bccontainerhelper -Force
$module = Get-InstalledModule -Name bccontainerhelper -ErrorAction Ignore
$versionStr = $module.Version.ToString()
Write-Host "##[section]BcContainerHelper $VersionStr installed"
#install bccontainerhelper

$authContext = New-BcAuthContext -refreshToken $env:refreshToken -tenantID $env:TENANTID

$ArtifactsDirectory = (Join-Path -Path $env:System_ArtifactsDirectory -ChildPath ($env:Release_PrimaryArtifactSourceAlias + '\Artifacts'))
$AppFile = Get-ChildItem -Path $ArtifactsDirectory -Filter "*.app"
write-host "##[section]App file" $AppFile.FullName
write-host "##[section]Publishing app to tenant:" $env:TENANTID "Environment:" $env:ENVIRONMENT
Publish-PerTenantExtensionApps `
    -bcAuthContext $authContext `
    -environment $env:ENVIRONMENT `
    -appFiles $AppFile.FullName `
    -schemaSyncMode Force

Release pipeline

In your project create release pipeline

Script Path: 

$(System.DefaultWorkingDirectory)/$(Release.PrimaryArtifactSourceAlias)/Artifacts/PublishApp.ps1

or different branch which you are using for sandbox environement

Run command

Command: 

$AuthContext = New-BcAuthContext -includeDeviceLogin
Get-ALGoAuthContext -bcAuthContext $AuthContext | Set-Clipboard

Command copied from Freddy blog post

 

To get required data for publishing app

After that, go to Release and add Pipeline variables

After that you should be able to publish app to Sandbox environment.

For Production environment, the procedure is the same, only you have to specify Production environment name in release pipeline.

and specify artifact for main branch(or branch which you are using for Production environment)

Conclusion

This blog post brings together a complete CI/CD process of developing a simple application for Microsoft Dynamics 365 Business Central. The following posts will provide a demonstration of how to define build pipelines on Self Hosted agents and deploy them to OnPrem environments.



Add comment

Comments

khoi Vu
a year ago

Greate tks , it is really helpful :)