Skip to content

Instantly share code, notes, and snippets.

@i-b1
Created January 6, 2020 21:33
Show Gist options
  • Save i-b1/38a42728cf036fbc1eea6efc2398c6f2 to your computer and use it in GitHub Desktop.
Save i-b1/38a42728cf036fbc1eea6efc2398c6f2 to your computer and use it in GitHub Desktop.
Azure Devops Build Pipeline for ASP.NET Core 3.* applications and C# Azure Functions
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects;
trigger: none
#- master
pool:
name: Hosted Windows 2019 with VS2019
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Use .NET SDK 2.1'
inputs:
packageType: 'sdk'
version: '2.1.x'
- task: UseDotNet@2
displayName: 'Use .NET SDK 3.0'
inputs:
packageType: 'sdk'
version: '3.0.x'
- task: DotNetCoreCLI@2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Install ReportGenerator'
inputs:
command: custom
custom: tool
arguments: 'install --global dotnet-reportgenerator-globaltool'
- task: DotNetCoreCLI@2
displayName: 'Run unit tests - $(buildConfiguration)'
inputs:
command: 'test'
arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
publishTestResults: true
projects: '**/Api.UnitTests.csproj'
- script: |
reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines
displayName: 'Create code coverage report'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
- task: DotNetCoreCLI@2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: 'publish'
projects: '**/MyProject.Api.csproj'
publishWebProjects: false
arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: MyProjectApi'
condition: succeeded()
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'MyProjectApi'
publishLocation: 'Container'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment