Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
210 lines (204 sloc) 7.77 KB
name: $(Version).$(rev:r)
variables:
- group: 'Pipeline Common'
- group: '.NET Core Common'
trigger:
branches:
include:
- master
paths:
exclude:
- '.editorconfig'
- '.gitignore'
- 'README.md'
- 'LICENSE'
- '*.sln'
- '**/*.csproj'
stages:
# Build Pipeline
- stage: Build
jobs:
- job: HostedVs2017
displayName: Hosted VS2017
pool:
name: Hosted VS2017
workspace:
clean: all
variables:
- name: UnitTestRunStatus
value: ''
- name: IntegrationTestRunStatus
value: ''
steps:
- task: CmdLine@2
displayName: 'Install MounteBank'
inputs:
script: 'npm install -g mountebank'
- task: CmdLine@2
displayName: 'Install Azure Functions CLI'
inputs:
script: 'npm install -g azure-functions-core-tools --unsafe-perm true'
- task: DotNetCoreInstaller@0
displayName: 'Install .NET Core SDK'
inputs:
version: $(SdkVersion)
- task: DotNetCoreCLI@2
displayName: 'Restore NuGet Packages'
inputs:
command: restore
projects: '$(Build.SourcesDirectory)/*.sln'
- task: DotNetCoreCLI@2
displayName: 'Build Function App'
inputs:
projects: '$(Build.SourcesDirectory)/*.sln'
arguments: '-c $(BuildConfiguration)'
- task: CmdLine@2
displayName: 'Run MounteBank'
inputs:
script: 'start /b mb --noLogFile'
- task: CmdLine@2
displayName: 'Run Function App'
inputs:
script: |
cd $(Build.SourcesDirectory)\src\FunctionApp
start /b func host start --csharp
env:
ExternalApi__BaseUri: http://localhost:8080/api
ExternalApi__Endpoints__HealthCheck: ping
- task: CmdLine@2
displayName: 'Unit Test Function App'
inputs:
script: 'dotnet test $(Build.SourcesDirectory)\test\FunctionApp.Tests\FunctionApp.Tests.csproj -c $(BuildConfiguration) --filter:"TestCategory!=Integration&TestCategory!=E2E" --logger:trx --results-directory:$(System.DefaultWorkingDirectory)\UnitTestResults /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(System.DefaultWorkingDirectory)\CoverageResults\coverage'
env:
ServerName: Localhost
continueOnError: true
- task: PowerShell@2
displayName: 'Save Unit Test Run Status'
inputs:
targetType: Inline
script: 'Write-Host "##vso[task.setvariable variable=UnitTestRunStatus]$(Agent.JobStatus)"'
- task: PublishTestResults@2
displayName: 'Publish Unit Test Results'
inputs:
testRunTitle: 'Unit Tests'
testResultsFormat: VSTest
testResultsFiles: '$(System.DefaultWorkingDirectory)/UnitTestResults/*.trx'
mergeTestResults: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/CoverageResults/*.xml'
failIfCoverageEmpty: false
- task: CmdLine@2
displayName: 'Integration Test Function App'
inputs:
script: 'dotnet test $(Build.SourcesDirectory)\test\FunctionApp.Tests\FunctionApp.Tests.csproj -c $(BuildConfiguration) --filter:"TestCategory=Integration" --logger:trx --results-directory:$(System.DefaultWorkingDirectory)\IntegrationTestResults'
env:
ServerName: Localhost
continueOnError: true
- task: PowerShell@2
displayName: 'Save Integration Test Run Status'
inputs:
targetType: Inline
script: 'Write-Host "##vso[task.setvariable variable=IntegrationTestRunStatus]$(Agent.JobStatus)"'
- task: PublishTestResults@2
displayName: 'Publish Integration Test Results'
inputs:
testRunTitle: 'Integration Tests'
testResultsFormat: VSTest
testResultsFiles: '$(System.DefaultWorkingDirectory)/IntegrationTestResults/*.trx'
mergeTestResults: true
- task: PowerShell@2
displayName: 'Cancel Pipeline on Test Run Failure'
condition: and(succeeded(), or(eq(variables['UnitTestRunStatus'], 'Failed'), eq(variables['UnitTestRunStatus'], 'SucceededWithIssues'), eq(variables['IntegrationTestRunStatus'], 'Failed'), eq(variables['IntegrationTestRunStatus'], 'SucceededWithIssues')))
inputs:
targetType: Inline
script: |
Write-Host "##vso[task.setvariable variable=Agent.JobStatus]Failed"
Write-Host "##vso[task.complete result=Failed]DONE"
- task: DotNetCoreCLI@2
displayName: 'Publish Function App'
inputs:
command: publish
publishWebProjects: false
projects: '$(System.DefaultWorkingDirectory)/src/FunctionApp/*.csproj'
arguments: '-c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)/app'
zipAfterPublish: false
- task: DotNetCoreCLI@2
displayName: 'Publish E2E Test App'
inputs:
command: publish
publishWebProjects: false
projects: '$(System.DefaultWorkingDirectory)/test/FunctionApp.Tests/*.csproj'
arguments: '-c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)/e2e'
zipAfterPublish: false
- task: PublishBuildArtifacts@1
displayName: 'Publish Function App Artifact'
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/app
artifactName: app
publishLocation: 'Container'
- task: PublishBuildArtifacts@1
displayName: 'Publish E2E Test App Artifact'
inputs:
pathToPublish: $(Build.ArtifactStagingDirectory)/e2e
artifactName: e2e
publishLocation: 'Container'
# Release Pipeline
- stage: Release
jobs:
- deployment: HostedVs2017
displayName: Hosted VS2017
pool:
name: Hosted VS2017
environment: fncapp
variables:
- group: 'Function App'
- name: TestRunStatus
value: ''
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Deploy Function App'
inputs:
azureSubscription: 'azure-resource-manager'
appType: functionApp
appName: $(FunctionAppName)
package: '$(Pipeline.Workspace)/app/FunctionApp'
deploymentMethod: runFromPackage
- task: DotNetCoreInstaller@0
displayName: 'Install .NET Core SDK'
inputs:
version: $(SdkVersion)
- task: CmdLine@2
displayName: 'Run E2E Tests'
inputs:
script: 'dotnet vstest $(Pipeline.Workspace)\e2e\FunctionApp.Tests\FunctionApp.Tests.dll --testCaseFilter:TestCategory=E2E --logger:trx --resultsDirectory:$(Pipeline.Workspace)\TestResults'
continueOnError: true
env:
ServerName: FunctionApp
FunctionAuthKey: $(FunctionAuthKey)
FunctionAppName: $(FunctionAppName)
- task: PowerShell@2
displayName: 'Save Test Run Status'
inputs:
targetType: Inline
script: 'Write-Host "##vso[task.setvariable variable=TestRunStatus]$(Agent.JobStatus)"'
- task: PublishTestResults@2
displayName: 'Publish E2E Test Results'
inputs:
testRunTitle: 'E2E Tests'
testResultsFormat: VSTest
testResultsFiles: '$(Pipeline.Workspace)/TestResults/*.trx'
mergeTestResults: true
- task: PowerShell@2
displayName: 'Cancel Pipeline on Test Run Failure'
condition: and(succeeded(), or(eq(variables['TestRunStatus'], 'Failed'), eq(variables['TestRunStatus'], 'SucceededWithIssues')))
inputs:
targetType: Inline
script: |
Write-Host "##vso[task.setvariable variable=Agent.JobStatus]Failed"
Write-Host "##vso[task.complete result=Failed]DONE"
You can’t perform that action at this time.