This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines.yml
147 lines (134 loc) · 4.05 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
trigger:
batch: true
branches:
include:
- master
- release/*
paths:
exclude:
- README.md
- docs/*
- physicals/*
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build
jobs:
- job: UnitTests
displayName: Unit Tests
workspace:
clean: all
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '5.0.x'
- task: DotNetCoreCLI@2
displayName: 'Ensure Report Generator on unit test projects'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
command: 'custom'
projects: '**/*UnitTest*.csproj'
custom: 'add'
arguments: 'package ReportGenerator'
- task: DotNetCoreCLI@2
displayName: 'Ensure coverlet.msbuild on unit test projects'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
command: 'custom'
projects: '**/*UnitTest*.csproj'
custom: 'add'
arguments: 'package coverlet.msbuild'
- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: 'test'
arguments: '--configuration Release --settings $(Build.SourcesDirectory)/src/CodeCoverage.runsettings /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
projects: '**/*UnitTest*.csproj'
- task: reportGenerator@4
displayName: 'Generate Coverage report'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges'
assemblyfilters: '-xunit*'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/TestResults/coverage'
- job: DockerBuild
displayName: 'Build Docker Image'
workspace:
clean: all
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
displayName: "Build docker image"
inputs:
containerRegistry: 'Docker Hub'
repository: 'matthewthomas/irrigationcontroller'
command: 'build'
Dockerfile: '**/Dockerfile'
tags: |
$(Build.BuildId)
latest
- job: CreateArtifact
displayName: 'Create Artifact'
condition: ne(variables['Build.Reason'], 'PullRequest')
dependsOn:
- UnitTests
- DockerBuild
workspace:
clean: all
pool:
vmImage: 'ubuntu-latest'
steps:
#If the docker file builds and the unit tests pass, then get it ready to go as an artifact
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.SourcesDirectory)/src'
Contents: '**'
TargetFolder: '$(Build.StagingDirectory)'
CleanTargetFolder: true
# Publish the app as an artifact
- publish: $(Build.StagingDirectory)
artifact: app
- stage: DeployToDockerHub
displayName: 'Deploy'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
dependsOn: Build
jobs:
- deployment: DeployToDockerHub
displayName: 'Deploy To Docker Hub'
workspace:
clean: all
pool:
vmImage: 'ubuntu-latest'
environment: DockerHub
strategy:
runOnce:
deploy:
steps:
# Download the published application artifact
- download: current
artifact: app
- task: Docker@2
displayName: "Build docker image"
inputs:
containerRegistry: 'Docker Hub'
repository: 'matthewthomas/irrigationcontroller'
command: 'buildAndPush'
Dockerfile: '$(Pipeline.Workspace)/app/Dockerfile'
tags: |
$(Build.BuildId)
latest