Skip to content

Instantly share code, notes, and snippets.

@mhagrelius
Created October 2, 2019 20:53
Show Gist options
  • Save mhagrelius/bba5370db289d90a701a0176a185ec2e to your computer and use it in GitHub Desktop.
Save mhagrelius/bba5370db289d90a701a0176a185ec2e to your computer and use it in GitHub Desktop.
Azure DevOps Pipeline Example
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
name: Default
variables:
buildConfiguration: 'Release'
steps:
- task: AzureKeyVault@1
inputs:
azureSubscription: 'Azure'
keyVaultName: 'sightglasskeyvault01'
secretsFilter: '*' # Options: editableOptions
- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: 'install dotnet-reportgenerator-globaltool --tool-path .'
displayName: 'installing reportgenerator'
- task: DotNetCoreCLI@2
inputs:
command: build
arguments: '--configuration $(buildConfiguration)'
displayName: 'Building solution'
# Example that requires 80% line coverage to pass this step
# See https://github.com/tonerdo/coverlet/blob/master/Documentation/MSBuildIntegration.md
- task: DotNetCoreCLI@2
inputs:
command: test
projects: '**/*Test/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Include="[SightGlass.*]*" /p:Exclude="[SightGlass.Test.*]*" /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\'
env:
Dropbox__ApiKey: $(DropboxApiKey)
Google__Credentials__EmailAddress: $(GoogleAppEmailAddress)
Google__Credentials__PrivateKey: $(Google--Credentials--PrivateKey)
Testing__client_id: $(ClientId)
Testing__client_secret: $(ClientSecret)
Testing__resource: $(Resource)
Testing__tenant_id: $(TenantId)
ConnectionStrings__Mapcon: $(MapconConnectionString)
ConnectionStrings__Dataparc: $(DataparcConnectionString)
ConnectionStrings__SightGlass: $(ConnectionStrings--SightGlass)
displayName: 'Running tests'
- script: .\reportgenerator "-reports:$(Build.SourcesDirectory)\TestResults\Coverage\**\*.cobertura.xml" "-targetdir:$(Build.SourcesDirectory)\TestResults\Coverage\Reports" -tag:$(Build.BuildNumber) -reportTypes:HtmlInline_AzurePipelines;HTMLChart
displayName: 'Generating test reports'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)\TestResults\Coverage\**\coverage.cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)\TestResults\Coverage\Reports'
- task: DotNetCoreCLI@2
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory) /p:WebPublishMethod=Package /p:PackageAsSingleFile=true'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory)
artifactName: 'drop'
@mhagrelius
Copy link
Author

Note, there are some improvements that have been made in the last 12 months to coverlet and azure pipelines that allow some of the configuration to be streamlined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment