Introduction
In modern software development, Continuous Integration and Continuous Deployment (CI/CD) are crucial in ensuring smooth, automated deployments. Azure DevOps provides robust pipeline capabilities that enable developers to automate the deployment of their applications, reducing manual effort and minimizing errors.
In this blog, we’ll walk through setting up an Azure DevOps pipeline for an Azure Service App, ensuring seamless deployment whenever changes are pushed to the repository.
Setting Up the Azure DevOps Pipeline
Before diving into the pipeline configuration, ensure you have.
- An Azure Service App created in the Azure Portal.
- A service connection in Azure DevOps is linked to your Azure subscription.
- Your Service App code is stored in a repository like Azure Repos, GitHub, or Bitbucket.
Pipeline Configuration
Below is a YAML-based Azure DevOps pipeline that automates the build and deployment of an Azure Service App.
trigger:
branches:
include:
- main # Change this to your branch if needed
paths:
include:
- ServiceAppCode/*
variables:
azureSubscription: 'ServiceAppDeployment' # Azure service connection name
serviceAppName: 'TestingApp' # Azure Service App name
serviceAppPath: 'ServiceAppCode' # Path to Service App source code
buildConfiguration: 'Release' # Build service app source code in release
publishDirectory: '$(Build.ArtifactStagingDirectory)/publish'
pool:
vmImage: 'ubuntu-22.04' # Also use ubuntu-latest
stages:
- stage: Build
displayName: 'Build Stage'
jobs:
- job: Build
displayName: 'Build Job'
steps:
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: 'sdk'
version: '8.0.x'
includePreviewVersions: false
- script: |
echo "Cleaning up existing publish directory..."
rm -rf $(publishDirectory)
mkdir -p $(publishDirectory)
displayName: 'Ensure Clean Publish Directory'
- task: DotNetCoreCLI@2
displayName: 'Restore Dependencies'
inputs:
command: 'restore'
projects: '$(serviceAppPath)/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build Service App'
inputs:
command: 'build'
projects: '$(serviceAppPath)/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:WarningLevel=0' # Remove warnings during build
- task: DotNetCoreCLI@2
displayName: 'Publish Service App'
inputs:
command: 'publish'
projects: '$(serviceAppPath)/*.csproj'
publishWebProjects: false
arguments: '--configuration $(buildConfiguration) --output $(publishDirectory)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
pathToPublish: '$(publishDirectory)'
artifactName: 'drop'
- stage: Deploy
displayName: 'Deploy Stage'
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy to Azure Service App'
steps:
- download: current
displayName: 'Download Build Artifacts'
artifact: 'drop'
- task: AzureServiceApp@1
displayName: 'Deploy to Azure Service App'
inputs:
azureSubscription: '$(azureSubscription)'
appType: 'webApp' # functionApp for function app OR webApp for service app
appName: '$(serviceAppName)'
package: '$(Pipeline.Workspace)/drop/*.zip'
Join the conversation! Your thoughts help the community grow.