How to do it...

  1. In your web browser, navigate to https://dev.azure.com and log in with your Azure DevOps account.
  2. Open the televisionShow project.
  3. On the left side menu, select Pipelines | Builds.
  1. Click New pipeline.
  1. Click Azure Repos Git:

  1. Select the televisionShow repository.
  2. Select Starter pipeline. After a few moments, your build pipeline will be created and you will be presented with some sample YAML code.
  3. Click Save and run.
  4. Make sure that Commit directly to the master branch is selected and press Save and run:

In the next few moments, the sample build pipeline will execute, and if all goes well, then you'll end up with a result like this:

  1. In the top-right corner of the screen, click the  button and select Edit pipeline.
  2. Clear out all the existing code in the pipeline file.
  3. Add the following code to the pipeline:
trigger:
branches:
include:
- master

pool:
name: televisionShow-local

workspace:
clean: all

The preceding code does the following:

  • Configures the pipeline to execute using the master branch
  • Sets the agent pool to the one we created in the Installing a pipeline agent recipe earlier in this chapter 
  • Configures the pipeline to remove all existing files from the pipeline agent's working folders every time the pipeline is executed
  1. Add the following code to the pipeline file:
variables:
containerName: build
containerUserName: admin
containerPassword: Pass@word1
imageName: mcr.microsoft.com/businesscentral/sandbox:us
agentFolder: $env:agentfolder

The preceding code does the following:

  • Sets the name of the Business Central container that will be created during the pipeline process
  • Sets the login and password that will be used to create the Business Central container
  • Configures the Docker image that will be used to create the Business Central container
  • Sets the folder that will be shared with the Business Central container
Note the $env:agentFolder variable used in the preceding code. This is a predefined environment variable that is part of the build pipeline. You can find out what other predefined variables are available at https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml.
  1. Add the following code, which adds a task to the pipeline that runs some PowerShell code, in order to install NavContainerHelper:
steps:
- task: PowerShell@2
displayName: 'Install NavContainerHelper'
inputs:
targetType: inline
errorActionPreference: stop
failOnStderr: true
script:
Write-Host "Installing NavContainerHelper"
Install-Module -Name navcontainerhelper -Force

For PowerShell tasks in the pipeline, you can choose to code your script inline (for example, directly within the pipeline script) as we did previously, or you can choose to execute an external PowerShell script that can exist within the repository or another location.
  1. Now, add some code that contains another PowerShell task. This task will create the Business Central container that we'll use to build our application:
- task: PowerShell@2
displayName: 'Create Build Container'
inputs:
targetType: inline
errorActionPreference: stop
failOnStderr: true
script:
New-NavContainer -containerName $(containerName) `
-accept_eula `
-accept_outdated `
-auth NavUserPassword `
-Credential (New-Object pscredential $(containerUserName),
(ConvertTo-SecureString -String $(containerPassword) -
AsPlainText -Force)) `
-doNotExportObjectsToText `
-imageName $(imageName) `
-alwaysPull `
-shortcuts None `
-restart no `
-updateHosts `
-useBestContainerOS `
-assignPremiumPlan `
-additionalParameters @("--volume
""$($env:Agent_HomeDirectory):C:Agent""")
  1. Now, add a new task to the pipeline in order to build our AL application:
- task: PowerShell@2
displayName: 'Build AL application'
inputs:
targetType: inline
errorActionPreference: stop
failOnStderr: true
script:
Compile-AppInNavContainer -containerName $(containerName) `
-credential (New-Object pscredential $(containerUserName),
(ConvertTo-SecureString -String $(containerPassword) -
AsPlainText -Force)) `
-appProjectFolder $env:Build_SourcesDirectory `
-appOutputFolder $env:Build_StagingDirectory `
-UpdateSymbols `
-AzureDevOps `
-FailOn error | Out-Null
  1. Add a task to the pipeline to publish the Business Central application once it's been built:
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.StagingDirectory)'
artifactName: televisionShowApp

This will allow users to download the application from the completed build, and will also allow you to use the application in a release pipeline.

  1. Now, add the final task to remove the container that was created during the pipeline:
- task: PowerShell@2
displayName: 'Remove container'
condition: always()
continueOnError: true
inputs:
targetType: inline
failOnStderr: false
script:
Remove-NavContainer -containerName $(containerName)
Note that we use condition: always() to make sure that whether or not the previous pipeline task passes, this task will be executed. This way, we never leave a container running once the pipeline has completed.
  1. In the top-right corner of the screen, click Save.
  2. Make sure that Commit directly to the master branch is selected and click Save.
  3. In the top-right corner of your screen, click Run.
  4. You will see a message similar to the following that indicates whether the build pipeline has been queued for execution: 

Click the build number to view the real-time status of the build:

It may take 10 – 20 minutes to execute the build pipeline the first time, depending on the speed of the machine that is executing the build. This is because the Docker image needs to be downloaded. Unless the image is updated and needs to be downloaded again, subsequent runs of the build pipeline will be much shorter.
  1. Now, let's make sure that the build is executed when we commit a change to the repository. In Visual Studio Code, open the televisionShow folder that you connected to the Azure DevOps repository in the Connecting an AL project to Azure DevOps recipe.
  1. Press the Synchronize Changes button at the bottom-left of the application window.
  2. In Explorer, select src/codeunit/Download Episode Information.al.
  3. Find the following code:
SuccessMessageTxt: Label 'Episode information has been downloaded.';

Replace the code with this:

SuccessMessageTxt: Label 'Episode information has successfully been downloaded.';
  1. In the left menu, click  and type changed success message in the Message box.
  2. Press Ctrl + Enter to commit the changes to your local repository.
  3. Press the Synchronize Changes button at the bottom-left corner of the application window to push the changes to Azure DevOps.
  4. In your web browser, navigate to Azure DevOps and go to the televisionShow project.
  5. On the left side menu, select Pipelines | Build. You should now see that a new build has been automatically queued:

  1. Once the build pipeline completes, you can grab the application that it created by clicking on the Artifacts button in the top-right corner of the build results page, and then selecting the name of the artifact, which, in our case, is televisionShowApp:

  1. Click the ... to download the Business Central application:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.124