Creating a pipeline in Azure DevOps to deploy a Business Central AL project to a sandbox environment involves several steps. Here’s a step-by-step guide to create an Azure DevOps pipeline that deploys your Business Central AL project to a sandbox environment.
Prerequisites:
- Azure DevOps Repository: You should have your Business Central AL project stored in an Azure DevOps repository.
- Business Central Sandbox Environment: Ensure you have access to a Business Central Sandbox environment and the necessary permissions to deploy.
- Azure DevOps Service Connection: Set up a service connection to connect Azure DevOps to your Business Central instance.
- Business Central Tenant Admin Role: Ensure you have the required permissions in the sandbox environment to deploy the AL app.
Steps to Create a Pipeline:
1. Create a New Pipeline in Azure DevOps:
- Go to your Azure DevOps organization and navigate to the Pipelines section.
- Click New Pipeline to start the pipeline creation wizard.
- Select your repository type (for example, Azure Repos Git).
- Choose the repository that contains your Business Central AL project.
2. Choose Pipeline Type:
- Select YAML for the pipeline configuration as it offers flexibility.
- If you prefer the classic UI editor, you can choose the Classic Editor instead. However, for this guide, we will use YAML.
3. Create YAML Pipeline Definition:
You will define a YAML pipeline that:
- Builds the AL extension.
- Deploys the AL extension to the Business Central sandbox environment.
Below is a sample YAML pipeline definition that automates this process.
Sample YAML Pipeline:
- main # Trigger the pipeline on changes to the 'main' branch, change to your branch if necessary.
pool:
vmImage: 'windows-latest'
variables:
bcSandboxUrl: 'https://your-sandbox-url' # Replace with your Business Central sandbox URL.
bcTenant: 'your-tenant-id' # Replace with your Business Central tenant ID.
bcEnvironment: 'sandbox' # Sandbox or another environment.
appFileName: 'YourAppName.al' # Name of your AL project file.
appPackage: 'YourAppName.app' # Output AL app package after building.
steps:
# Step 1: Checkout the repository.
- task: Checkout@1
# Step 2: Install dependencies (AL Language extension and Business Central tools)
- task: UseDotNet@2
displayName: 'Install AL dependencies'
inputs:
packageType: 'sdk'
installationPath: $(Agent.ToolsDirectory)/dotnet
# Step 3: Build the AL extension using AL: Compile
- task: ALBuild@1
displayName: 'Build AL Project'
inputs:
target: 'build'
outputPath: '$(Build.ArtifactStagingDirectory)'
buildConfiguration: 'Release'
# Step 4: Publish the AL app (artifact)
- task: PublishBuildArtifacts@1
displayName: 'Publish AL App Artifacts'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
publishLocation: 'Container'
# Step 5: Deploy to Business Central Sandbox
- task: InvokeAzureWebAppCommand@2
displayName: 'Deploy AL Extension to BC Sandbox'
inputs:
azureSubscription: 'Your Azure Subscription' # Service connection name for Azure DevOps.
appName: 'your-web-app-name' # Web app name, adjust according to your BC sandbox.
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
# Login to Business Central Environment
bcSandboxUrl="https://your-sandbox-url"
tenantId="your-tenant-id"
appId="your-app-id"
secret="your-app-secret"
artifact="path_to_your_build_artifact"
# Deploy the app (AL extension)
curl -X POST "$bcSandboxUrl/administration/applications/upload" \
-H "Authorization: Bearer $accessToken" \
-F "file=@$artifact"
echo "App deployed successfully."
workingDirectory: '$(Build.SourcesDirectory)'
# Step 6: Cleanup and finish.
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'ALAppPackage'
Explanation of Steps:
- trigger: This section triggers the pipeline automatically when there are changes to the
main
branch (you can modify this to the branch you’re working with). - pool: Defines the agent pool that will be used for the pipeline execution. The
windows-latest
image is typically used for building AL projects. - variables: Define variables like the sandbox URL, tenant ID, and app file name that can be reused across tasks.
- Checkout Task: This step checks out your code from the Azure repository.
- Install AL Dependencies: The
UseDotNet
task installs the necessary dependencies like the AL SDK. - Build AL Project: The
ALBuild@1
task compiles your AL extension into an.app
file. - Publish Build Artifacts: The
PublishBuildArtifacts@1
task makes the built.app
file available for later stages, like deployment. - Deploy to Sandbox: The
InvokeAzureWebAppCommand@2
task deploys the.app
file to your Business Central sandbox using a script. Thecurl
command is used to upload the app to the sandbox, and you’ll need to replace placeholders with actual values, such as sandbox URL, client credentials, and file paths. - Publish Pipeline Artifact: After deployment, you can store the deployment artifacts as part of the pipeline for future use.
4. Set Up the Azure Service Connection:
Before running the pipeline, ensure that you’ve created an Azure service connection in your Azure DevOps project to allow the pipeline to authenticate with your Business Central environment.
- Go to Project Settings > Service connections in Azure DevOps.
- Create a new service connection for Azure Resource Manager and configure it with the necessary permissions to your Business Central environment.
5. Save and Run the Pipeline:
- Once your YAML is configured, save the pipeline and trigger it by committing to your repository.
- You should see the pipeline executing in the Pipelines section of Azure DevOps.
- If everything is set up correctly, the AL app will be deployed to your sandbox environment.
Troubleshooting:
- Permissions: Make sure the account running the pipeline has sufficient permissions in Azure DevOps and Business Central.
- App Package Issues: Ensure the app file is built and published correctly before attempting deployment.
- Secrets: Use Azure Key Vault or Pipeline Secrets for securely handling credentials like the app secret or client ID.
By following these steps, you should be able to create an automated deployment pipeline for Business Central AL apps to a sandbox environment. Let me know if you need help with any specific part of the process!