|
| 1 | +parameters: |
| 2 | + - name: JobName |
| 3 | + displayName: 'Job Name' |
| 4 | + type: string |
| 5 | + |
| 6 | + - name: workingDirectoryForDocker |
| 7 | + displayName: 'Working directory for Docker Build' |
| 8 | + default: '$(System.DefaultWorkingDirectory)/src' |
| 9 | + type: string |
| 10 | + |
| 11 | + - name: solution |
| 12 | + displayName: 'Solution file path' |
| 13 | + type: string |
| 14 | + |
| 15 | + - name: buildConfiguration |
| 16 | + displayName: 'Build Configuration' |
| 17 | + default: 'Release' |
| 18 | + type: string |
| 19 | + |
| 20 | + - name: backendProjectPath |
| 21 | + displayName: 'Backend project path' |
| 22 | + type: string |
| 23 | + |
| 24 | + - name: unitTestsProjectPath |
| 25 | + displayName: 'Unit tests project path' |
| 26 | + default: '' |
| 27 | + type: string |
| 28 | + |
| 29 | + - name: shouldRunUnitTests |
| 30 | + displayName: 'Flag should run unit tests' |
| 31 | + default: true |
| 32 | + type: boolean |
| 33 | + |
| 34 | + - name: shouldRunIntegrationTests |
| 35 | + displayName: 'Flag should run integration tests' |
| 36 | + type: boolean |
| 37 | + |
| 38 | + - name: integrationTestsProjectPath |
| 39 | + displayName: 'Integration tests project path' |
| 40 | + type: string |
| 41 | + |
| 42 | + - name: gitVersionVersion |
| 43 | + displayName: 'GitVersion version' |
| 44 | + default: '6.x' |
| 45 | + type: string |
| 46 | + |
| 47 | + - name: dockerRegistryUrl |
| 48 | + type: string |
| 49 | + displayName: 'DockerHub Registry URL. For Docker Hub it is: docker.io/kaminome.' |
| 50 | + |
| 51 | + - name: shouldPushToDockerHub |
| 52 | + type: boolean |
| 53 | + default: false |
| 54 | + |
| 55 | + - name: shouldPushToAcr |
| 56 | + type: boolean |
| 57 | + default: false |
| 58 | + |
| 59 | + - name: acrRegistryUrl |
| 60 | + type: string |
| 61 | + displayName: 'ACR Registry URL. For ACR it is FQDN URL of container registry: azuredevopsacrd01.azurecr.io' |
| 62 | + |
| 63 | + - name: imageRepository |
| 64 | + displayName: 'Image Repository name' |
| 65 | + type: string |
| 66 | + |
| 67 | + - name: dockerfilePath |
| 68 | + displayName: 'Dockerfile path' |
| 69 | + type: string |
| 70 | + |
| 71 | + - name: dockerServiceConnection |
| 72 | + displayName: 'Docker container registry service connection in Azure DevOps.' |
| 73 | + type: string |
| 74 | + |
| 75 | + - name: acrServiceConnection |
| 76 | + displayName: 'Azure container registry service connection in Azure DevOps.' |
| 77 | + type: string |
| 78 | + |
| 79 | + - name: dockerBuildParameterUrl |
| 80 | + displayName: 'Build parameter for Docker: Base URL' |
| 81 | + default: 'https://auth.eventtriangle.razumovsky.me/' |
| 82 | + type: string |
| 83 | + |
| 84 | + - name: dotnetSdkVersion |
| 85 | + type: string |
| 86 | + default: '10.x' |
| 87 | + |
| 88 | + - name: sonarCloudEnabled |
| 89 | + type: boolean |
| 90 | + default: false |
| 91 | + |
| 92 | + - name: sonarCloudServiceConnection |
| 93 | + type: string |
| 94 | + default: SonarCloud_Service_Connection |
| 95 | + |
| 96 | +jobs: |
| 97 | + - job: ${{ parameters.JobName }} |
| 98 | + displayName: ${{ parameters.JobName }} |
| 99 | + steps: |
| 100 | + - checkout: self |
| 101 | + fetchDepth: 0 |
| 102 | + |
| 103 | + - task: UseDotNet@2 |
| 104 | + displayName: 'Install .NET SDK ${{ parameters.dotnetSdkVersion }}' |
| 105 | + condition: succeeded() |
| 106 | + inputs: |
| 107 | + packageType: 'sdk' |
| 108 | + version: '${{ parameters.dotnetSdkVersion }}' |
| 109 | + |
| 110 | + - task: gitversion-setup@4.5.0 |
| 111 | + displayName: 'GitVersion Setup' |
| 112 | + condition: succeeded() |
| 113 | + inputs: |
| 114 | + versionSpec: ${{ parameters.gitVersionVersion }} |
| 115 | + |
| 116 | + - task: gitversion-execute@4.5.0 |
| 117 | + name: version_step # step id used as a reference for output values |
| 118 | + displayName: Determine Version |
| 119 | + condition: succeeded() |
| 120 | + |
| 121 | + - bash: echo $Action$BuildVersion |
| 122 | + displayName: 'Set Build Version' |
| 123 | + condition: succeeded() |
| 124 | + env: |
| 125 | + Action: '##vso[build.updatebuildnumber]' |
| 126 | + BuildVersion: $(version_step.semVer) |
| 127 | + |
| 128 | + - pwsh: | |
| 129 | + Write-Host "=== ENV VARIABLES ===" |
| 130 | + Get-ChildItem Env: | Sort-Object Name |
| 131 | +
|
| 132 | + Write-Host "=== PIPELINE VARIABLES ===" |
| 133 | + Write-Host "FullSemVer: $(version_step.FullSemVer)" |
| 134 | + Write-Host "SemVer: $(version_step.SemVer)" |
| 135 | + Write-Host "ShortSha: $(version_step.ShortSha)" |
| 136 | + Write-Host "Build Source branch: $env:BUILD_SOURCEBRANCHNAME" |
| 137 | + displayName: Debug environment |
| 138 | + condition: succeeded() |
| 139 | +
|
| 140 | + # - task: PowerShell@2 |
| 141 | + # displayName: 'Debug branch condition' |
| 142 | + # condition: ne(variables['Build.SourceBranchName'], 'main') |
| 143 | + # inputs: |
| 144 | + # targetType: 'inline' |
| 145 | + # script: | |
| 146 | + # Write-Host "Running because branch is NOT main" |
| 147 | + # Write-Host "Branch: $env:BUILD_SOURCEBRANCHNAME" |
| 148 | + |
| 149 | + - task: DotNetCoreCLI@2 |
| 150 | + displayName: 'Dotnet restore' |
| 151 | + condition: succeeded() |
| 152 | + inputs: |
| 153 | + command: 'restore' |
| 154 | + projects: '${{ parameters.solution }}' |
| 155 | + arguments: '--verbosity minimal' |
| 156 | + nugetConfigPath: 'nuget.config' |
| 157 | + |
| 158 | + - task: SonarCloudPrepare@4 |
| 159 | + condition: and( |
| 160 | + succeeded(), |
| 161 | + ${{ parameters.sonarCloudEnabled }}, |
| 162 | + eq(variables['Build.SourceBranchName'], 'main')) |
| 163 | + inputs: |
| 164 | + SonarCloud: ${{ parameters.sonarCloudServiceConnection }} |
| 165 | + organization: event-triangle |
| 166 | + scannerMode: dotnet |
| 167 | + projectKey: event-triangle-api |
| 168 | + projectName: eventtriangleapi |
| 169 | + extraProperties: | |
| 170 | + sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/**/*.trx |
| 171 | + sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*opencover.xml |
| 172 | + sonar.exclusions=**/Properties/**, **/bin/**, **/obj/**, **/Migrations/** |
| 173 | +
|
| 174 | + - task: DotNetCoreCLI@2 |
| 175 | + displayName: 'Build solution' |
| 176 | + condition: succeeded() |
| 177 | + inputs: |
| 178 | + command: 'build' |
| 179 | + projects: '${{ parameters.solution }}' |
| 180 | + arguments: '-c ${{ parameters.buildConfiguration }} -p:Version=$(version_step.semVer) --no-restore' |
| 181 | + |
| 182 | + - task: SonarCloudAnalyze@4 |
| 183 | + condition: and( |
| 184 | + succeeded(), |
| 185 | + ${{ parameters.sonarCloudEnabled }}, |
| 186 | + eq(variables['Build.SourceBranchName'], 'main')) |
| 187 | + inputs: {} |
| 188 | + |
| 189 | + - task: SonarCloudPublish@4 |
| 190 | + condition: and( |
| 191 | + succeeded(), |
| 192 | + ${{ parameters.sonarCloudEnabled }}, |
| 193 | + eq(variables['Build.SourceBranchName'], 'main')) |
| 194 | + inputs: |
| 195 | + pollingTimeoutSec: "300" |
| 196 | + |
| 197 | + - task: DotnetCoreCLI@2 |
| 198 | + displayName: 'Run unit tests' |
| 199 | + condition: and(succeeded(), eq(${{ parameters.shouldRunUnitTests }}, true)) |
| 200 | + inputs: |
| 201 | + command: 'test' |
| 202 | + projects: '${{ parameters.unitTestsProjectPath }}' |
| 203 | + arguments: '--no-build --configuration ${{ parameters.buildConfiguration }} --collect "Code Coverage"' |
| 204 | + |
| 205 | + - task: DotNetCoreCLI@2 |
| 206 | + displayName: 'Run integration tests' |
| 207 | + condition: and(succeeded(), eq(${{ parameters.shouldRunIntegrationTests }}, true)) |
| 208 | + inputs: |
| 209 | + command: 'test' |
| 210 | + projects: '${{ parameters.integrationTestsProjectPath }}' |
| 211 | + arguments: '--no-build --configuration ${{ parameters.buildConfiguration }} --collect "Code Coverage"' |
| 212 | + |
| 213 | + # - task: PowerShell@2 |
| 214 | + # displayName: 'Build Docker Image' |
| 215 | + # condition: succeeded() |
| 216 | + # inputs: |
| 217 | + # targetType: 'filePath' |
| 218 | + # filePath: '$(System.DefaultWorkingDirectory)/scripts/Build-Docker.ps1' |
| 219 | + # arguments: "-DockerRegistryUrl ${{ parameters.dockerRegistryUrl }} |
| 220 | + # -ImageRepository ${{ parameters.imageRepository }} |
| 221 | + # -AcrRegistryUrl ${{ parameters.acrRegistryUrl }} |
| 222 | + # -DockerBuildParameterUrl ${{ parameters.dockerBuildParameterUrl }} |
| 223 | + # -DockerfilePath ${{ parameters.dockerfilePath }} |
| 224 | + # -GitVersion $(version_step.semVer) |
| 225 | + # -WorkingDirectory ${{ parameters.workingDirectoryForDocker }} |
| 226 | + # -CommitSha $(version_step.ShortSha)" |
| 227 | + # errorActionPreference: 'stop' |
| 228 | + # pwsh: true |
| 229 | + |
| 230 | + # - task: Docker@2 |
| 231 | + # displayName: 'Push to DockerHub' |
| 232 | + # condition: and(succeeded(), eq(${{ parameters.shouldPushToDockerHub }}, true)) |
| 233 | + # inputs: |
| 234 | + # command: push |
| 235 | + # containerRegistry: ${{ parameters.dockerServiceConnection }} |
| 236 | + # repository: ${{ parameters.dockerRegistryUrl }}/${{ parameters.imageRepository }} |
| 237 | + # tags: | |
| 238 | + # $(version_step.semVer) |
| 239 | + # $(version_step.semVer)-$(version_step.ShortSha) |
| 240 | + # latest |
| 241 | + |
| 242 | + # - task: Docker@2 |
| 243 | + # displayName: 'Push to ACR' |
| 244 | + # condition: and(succeeded(), eq(${{ parameters.shouldPushToAcr }}, true)) |
| 245 | + # inputs: |
| 246 | + # command: push |
| 247 | + # containerRegistry: ${{ parameters.acrServiceConnection }} |
| 248 | + # repository: ${{ parameters.imageRepository }} |
| 249 | + # tags: | |
| 250 | + # $(version_step.semVer) |
| 251 | + # $(version_step.semVer)-$(version_step.ShortSha) |
| 252 | + # latest |
0 commit comments