Skip to content

Instantly share code, notes, and snippets.

@ntxinh
Last active January 15, 2021 04:50
Show Gist options
  • Save ntxinh/f0eab4d304733508a860b0a07792de03 to your computer and use it in GitHub Desktop.
Save ntxinh/f0eab4d304733508a860b0a07792de03 to your computer and use it in GitHub Desktop.
.NET Azure Pipeline multiple stage
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
trigger: [dev, main]
pr: [dev, main]
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
stages:
- stage: build
displayName: Build
variables:
- group: DEV
jobs:
- job: DevCI
steps:
- script: echo -----CI-----
displayName: Echo
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: 'restore'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: 'publish'
publishWebProjects: false
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Artifact
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: deploy_dev
displayName: Deploy to development
dependsOn:
- build
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'dev'))
variables:
- group: DEV
jobs:
- deployment: DeployWeb
environment: DEV
strategy:
runOnce:
deploy:
steps:
- script: echo -----CD-----
displayName: Echo
- task: AzureRmWebAppDeployment@4
displayName: Deploy
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(Subscription)'
appType: 'webApp'
WebAppName: '$(WebAppName)'
packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'
- stage: deploy_prod
displayName: Deploy to production
dependsOn:
- build
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
variables:
- group: PRD
jobs:
- deployment: DeployWeb
environment: PRD
strategy:
runOnce:
deploy:
steps:
- script: echo -----CD-----
displayName: Echo
- task: AzureRmWebAppDeployment@4
displayName: Deploy
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(Subscription)'
appType: 'webApp'
WebAppName: '$(WebAppName)'
packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment