Skip to content

Instantly share code, notes, and snippets.

@ievgen-pavlenko
Created May 13, 2023 06:16
Show Gist options
  • Save ievgen-pavlenko/bedf5e3023561a8e6e0c5489d85e0a37 to your computer and use it in GitHub Desktop.
Save ievgen-pavlenko/bedf5e3023561a8e6e0c5489d85e0a37 to your computer and use it in GitHub Desktop.
This YAML script is an Azure DevOps pipeline configuration for building, testing, and deploying an ASP.NET Core application to both Test and Production environments, with the Production deployment requiring a successful Test deployment and utilizing slot swapping for zero-downtime deployment.
trigger:
- main
stages:
- stage: Build
displayName: 'Build and Test'
jobs:
- job: BuildJob
displayName: 'Build Job'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DotNetCoreCLI@2
displayName: 'Restore Packages'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build Solution'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*Tests/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Publish Artifacts'
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Upload Artifacts'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
- stage: DeployTest
displayName: 'Deploy to Test Environment'
dependsOn: Build
condition: succeeded('Build')
jobs:
- deployment: DeployTestJob
displayName: 'Deploy Test Job'
environment: 'Test'
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Artifacts'
inputs:
buildType: 'current'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureWebApp@1
displayName: 'Deploy to Test Environment'
inputs:
azureSubscription: '$(AzureSubscriptionName)'
appName: '$(AppServiceName)'
appType: 'webApp'
package: '$(System.ArtifactsDirectory)/drop/**/*.zip'
slotName: 'staging'
- stage: DeployProduction
displayName: 'Deploy to Production Environment'
dependsOn: DeployTest
condition: succeeded('DeployTest')
jobs:
- deployment: DeployProductionJob
displayName: 'Deploy Production Job'
environment: 'Production'
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: AzureAppServiceManage@0
displayName: 'Swap Slots'
inputs:
azureSubscription: '$(AzureSubscriptionName)'
action: 'Swap Slots'
webAppName: '$(AppServiceName)'
ResourceGroupName: '$(RgName)'
sourceSlot: 'staging'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment