To be honest this is one of those blog posts that I have been having an inner struggle about rather or not to write. The reason being that there already are so many posts on the subject, but the reason I decided to write it anyway is because I feel that many posts over complicate it. So, in this post I will try to make it as simple as possible, however it is expected that you already have a working knowledge of Azure Dev Ops and PowerShell since I will not cover these in this post.
To get started with your pipelines you are going to need an azure agent running on a server, Microsoft has made a good how to guide on setting this up which can be found here https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser
Next you have to go your Azure DevOps project and go to the menu Pipelines and choose create Pipeline.
Choose Azure Git Repos
Select your Project and Repository, and choose starter pipeline.
This will generate a very simple YAML file for you.
Before you can start there are some things that you need to setup on your server, first off your need to install docker, next you need to install navcontainerhelper, and lastly you need to copy your licenses file to the server (this can be done more elegantly, but this is just to keep it simple)
Now replace the content of your simple YAML file with the following.
variables: containerName: Build image: mcr.microsoft.com/businesscentral/sandbox:dk LicenseFile: C:\License\MyLicense.flf ArtifactName: MyDevAtrifact system.debug: false trigger: - master pool: name: Default #Using default agent pool demands: docker #Agent must support docker steps: - checkout: self submodules: true - task: PowerShell@2 inputs: targetType: 'inline' script: | $credential = [PSCredential]::new("admin", (ConvertTo-SecureString -String "123456789" -AsPlainText -Force)) New-NavContainer -accept_eula -containerName $(containerName) -imageName $(image) -auth NavUserPassword -licenseFile $(LicenseFile) -Credential $credential -isolation hyperv -updateHosts - task: CopyFiles@2 inputs: Contents: '**' TargetFolder: 'C:\ProgramData\NavContainerHelper\Extensions\$(containerName)\my' OverWrite: true - task: PowerShell@2 inputs: targetType: 'inline' script: | $credential = [PSCredential]::new("admin", (ConvertTo-SecureString -String "123456789" -AsPlainText -Force)) Compile-AppInNavContainer -appProjectFolder C:\ProgramData\NavContainerHelper\Extensions\$(containerName)\my\app -containerName $(containerName) -AzureDevOps -EnablePerTenantExtensionCop -EnableCodeCop -EnableUICop -FailOn error -credential $credential $appFile = Get-ChildItem -Path C:\ProgramData\NavContainerHelper\Extensions\$(containerName)\my\app\output\*.app -Recurse -Force Publish-NavContainerApp -appFile $appfile -containerName $(containerName) -install -skipVerification -sync -syncMode ForceSync - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '"C:\ProgramData\NavContainerHelper\Extensions\$(containerName)\my\app\output\"' ArtifactName: $(ArtifactName) publishLocation: 'Container'
What this script will do is download the code in your master branch, create a new docker container, compile and publish your app to the container and lastly create a new build artifact.
And that is all there is to creating a build pipeline, coming up in the next posts I will clean this YAML file up so that is uses templates making it more clean, and we will also look at what you have to do if your app has dependencies, so stay tuned.