Created
April 22, 2020 18:06
-
-
Save MarcusFelling/59fd9d150a07e054cf67f4deb4e6919f to your computer and use it in GitHub Desktop.
YAML pipeline for Space Game webb app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: $(Major).$(Minor).$(Patch) | |
variables: | |
buildConfiguration: 'Release' | |
dotnetSdkVersion: '2.1.505' | |
serviceConnection: 'tailspin-space-game-rg' | |
appName: 'tailspin-space-game-web' | |
appID: '26178' | |
SITE_URL: 'https://$(appName)-$(System.StageName)-$(appID).azurewebsites.net' | |
wwwrootDir: 'Tailspin.SpaceGame.Web/wwwroot' | |
Major: '1' | |
Minor: '1' | |
Patch: $[counter(format('{0}.{1}', variables['Major'], variables['Minor']), 0)] | |
stages: | |
- stage: 'Build' | |
displayName: 'Build the web application' | |
jobs: | |
- job: 'Build' | |
displayName: 'Build job' | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
demands: | |
- npm | |
steps: | |
- task: DotNetCoreInstaller@0 | |
displayName: 'Use .NET Core SDK $(dotnetSdkVersion)' | |
inputs: | |
version: '$(dotnetSdkVersion)' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Install ReportGenerator' | |
inputs: | |
command: custom | |
custom: tool | |
arguments: 'install --global dotnet-reportgenerator-globaltool' | |
- task: Npm@1 | |
displayName: 'Run npm install' | |
inputs: | |
verbose: false | |
- script: './node_modules/.bin/node-sass $(wwwrootDir) --output $(wwwrootDir)' | |
displayName: 'Compile Sass assets' | |
- task: gulp@1 | |
displayName: 'Run gulp tasks' | |
- script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt' | |
displayName: 'Write build info' | |
workingDirectory: $(wwwrootDir) | |
- 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: '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: '**/*.Tests.csproj' | |
testRunTitle: 'Unit Tests' | |
- 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: '**/Tailspin.SpaceGame.Web.csproj' | |
publishWebProjects: false | |
arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)' | |
zipAfterPublish: true | |
- publish: '$(Build.ArtifactStagingDirectory)' | |
artifact: drop | |
- job: BuildDacpac | |
pool: | |
vmImage: 'windows-2019' | |
steps: | |
- task: DotNetCoreCLI@2 | |
displayName: 'Restore project dependencies' | |
inputs: | |
command: 'restore' | |
projects: '**/*.csproj' | |
- task: VSBuild@1 | |
displayName: 'Build the database project' | |
inputs: | |
project: '**/*.sqlproj' | |
- task: CopyFiles@2 | |
displayName: 'Copy dacpac file to staging directory' | |
inputs: | |
contents: | | |
Tailspin.SpaceGame.Database/bin/**/*.dacpac | |
targetFolder: '$(Build.StagingDirectory)' | |
- task: PublishBuildArtifacts@1 | |
displayName: 'Publish Artifact' | |
inputs: | |
pathToPublish: '$(Build.ArtifactStagingDirectory)' | |
artifactName: dropDacpac | |
condition: succeededOrFailed() | |
- stage: DBAVerificationScript | |
displayName: 'Script database schema changes' | |
dependsOn: Build | |
jobs: | |
- deployment: DBAVerificationScript | |
pool: | |
vmImage: 'windows-2019' | |
variables: | |
- group: 'Release' | |
environment: 'dbaverificationscript' | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: dropDacpac | |
patterns: '**/*' | |
- task: SqlAzureDacpacDeployment@1 | |
displayName: Generate schema change script | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
authenticationType: 'server' | |
serverName: '$(servername).database.windows.net' | |
databaseName: '$(databasename)' | |
sqlUsername: '$(adminlogin)' | |
sqlPassword: '$(adminPassword)' | |
deployType: 'DacpacTask' | |
deploymentAction: 'Script' | |
dacpacFile: '$(Pipeline.Workspace)/dropDacpac/Tailspin.SpaceGame.Database/bin/Debug/Tailspin.SpaceGame.Database.dacpac' | |
ipDetectionMethod: 'AutoDetect' | |
- task: PowerShell@2 | |
displayName: Show Auto Generated SQL Script | |
inputs: | |
targetType: 'inline' | |
script: | | |
Write-Host "Auto Generated SQL Update Script:" | |
Get-Content $(Build.SourcesDirectory)\GeneratedOutputFiles\$(databasename)_Script.sql | foreach {Write-Output $_} | |
- task: PowerShell@2 | |
displayName: Show change script and check for schema changes | |
inputs: | |
targetType: 'inline' | |
script: | | |
# Print the schema change script | |
Write-Host "Auto Generated SQL Update Script:" | |
Get-Content $(Build.SourcesDirectory)\GeneratedOutputFiles\$(databasename)_Script.sql | foreach {Write-Output $_} | |
# Check for schema changes | |
$file = Get-Content "$(Build.SourcesDirectory)\GeneratedOutputFiles\$(databasename)_Script.sql" | |
$containsWord = $file | %{$_ -match "CREATE" -or $_ -match "ALTER" -or $_ -match "DROP"} | |
if ($containsWord -contains $true) { | |
Install-Module VSTeam -Scope CurrentUser -Force | |
Set-VSTeamAccount –Account $(System.CollectionUri) -PersonalAccessToken $(PAT) | |
$methodParameters = @{ | |
ProjectName = "$(System.TeamProject)" | |
Name = "Release"} | |
$vg = Get-VSTeamVariableGroup @methodParameters | |
$vars = @{} | |
$vg.variables | Get-Member -MemberType *Property | %{$vars.($_.Name) = $vg.variables.($_.Name)} | |
$varName = "schemaChanged" | |
$vars.$varName= @{} | |
$vars.$varName.value = "True" | |
$vars.$varName.isSecret = $false | |
$methodParameters = @{ | |
id = $vg.id | |
ProjectName = "$(System.TeamProject)" | |
Name = "Release" | |
Description = "" | |
Type = "Vsts" | |
Variables = $vars} | |
Update-VSTeamVariableGroup @methodParameters} | |
- stage: DBAVerificationApply | |
variables: | |
- group: 'Release' | |
displayName: 'Apply database schema changes' | |
dependsOn: DBAVerificationScript | |
condition: and(succeeded('DBAVerificationScript'), eq(variables['schemaChanged'], True)) | |
jobs: | |
- deployment: DBAVerificationApply | |
pool: | |
vmImage: 'windows-2019' | |
variables: | |
- group: 'Release' | |
environment: 'dbaverificationapply' | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: dropDacpac | |
patterns: '**/*' | |
- task: SqlAzureDacpacDeployment@1 | |
displayName: 'Deploy SQL schema' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
authenticationType: 'server' | |
serverName: '$(servername).database.windows.net' | |
databaseName: '$(databasename)' | |
sqlUsername: '$(adminlogin)' | |
sqlPassword: '$(adminPassword)' | |
deployType: 'DacpacTask' | |
deploymentAction: 'Publish' | |
dacpacFile: '$(Pipeline.Workspace)/dropDacpac/Tailspin.SpaceGame.Database/bin/Debug/Tailspin.SpaceGame.Database.dacpac' | |
ipDetectionMethod: 'AutoDetect' | |
- task: PowerShell@2 | |
displayName: 'Remove "schemaChanged" pipeline variable' | |
inputs: | |
targetType: 'inline' | |
script: | | |
Install-Module VSTeam -Scope CurrentUser -Force | |
Set-VSTeamAccount –Account $(System.CollectionUri) -PersonalAccessToken $(PAT) | |
$methodParameters = @{ | |
ProjectName = "$(System.TeamProject)" | |
Name = "Release"} | |
$vg = Get-VSTeamVariableGroup @methodParameters | |
$vars = @{} | |
$vg.variables | Get-Member -MemberType *Property | %{$vars.($_.Name) = $vg.variables.($_.Name)} | |
$vars.Remove("schemaChanged") | |
$methodParameters = @{ | |
id = $vg.id | |
ProjectName = "$(System.TeamProject)" | |
Name = "Release" | |
Description = "" | |
Type = "Vsts" | |
Variables = $vars} | |
Update-VSTeamVariableGroup @methodParameters | |
- stage: 'Dev' | |
displayName: 'Deploy to the dev environment' | |
dependsOn: | |
- DBAVerificationScript | |
- DBAVerificationApply | |
condition: | | |
and | |
( | |
succeeded('DBAVerificationScript'), | |
in(dependencies.DBAVerificationApply.result, 'Succeeded', 'Skipped') | |
) | |
jobs: | |
- deployment: Deploy | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
environment: dev | |
variables: | |
- group: Release | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: drop | |
- task: AzureWebApp@1 | |
displayName: 'Azure App Service Deploy: website' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
appName: '$(appName)-$(System.StageName)-$(appID)' | |
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip' | |
- task: AzureCLI@2 | |
displayName: 'Set connection string' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az webapp config connection-string set --name $(appName)-$(System.StageName)-$(appID) --resource-group $(serviceConnection) --connection-string-type SQLAzure --settings "DefaultConnection=Server=tcp:$(servername).database.windows.net,1433;Initial Catalog=$(databasename);Persist Security Info=False;User ID=$(adminlogin);Password=$(adminPassword);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | |
- stage: 'Test' | |
displayName: 'Deploy to the test environment' | |
dependsOn: Dev | |
condition: succeeded('Dev') | |
jobs: | |
- deployment: Deploy | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
environment: test | |
variables: | |
- group: 'Release' | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: drop | |
- task: AzureWebApp@1 | |
displayName: 'Azure App Service Deploy: website' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
appName: '$(appName)-$(System.StageName)-$(appID)' | |
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip' | |
- task: AzureCLI@2 | |
displayName: 'Set connection string' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az webapp config connection-string set --name $(appName)-$(System.StageName)-$(appID) --resource-group $(serviceConnection) --connection-string-type SQLAzure --settings "DefaultConnection=Server=tcp:$(servername).database.windows.net,1433;Initial Catalog=$(databasename);Persist Security Info=False;User ID=$(adminlogin);Password=$(adminPassword);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | |
- job: RunUITests | |
dependsOn: Deploy | |
displayName: 'Run UI tests' | |
pool: | |
vmImage: 'windows-2019' | |
variables: | |
- group: 'Release' | |
steps: | |
- task: PowerShell@2 | |
displayName: 'Output Chrome version installed on hosted-agent, to align ChromeDriver version in UI tests' | |
inputs: | |
targetType: 'inline' | |
script: '(Get-Item (Get-ItemProperty ''HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'').''(Default)'').VersionInfo' | |
- task: DotNetCoreInstaller@0 | |
displayName: 'Use .NET Core SDK $(dotnetSdkVersion)' | |
inputs: | |
version: '$(dotnetSdkVersion)' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Build the project - $(buildConfiguration)' | |
inputs: | |
command: 'build' | |
arguments: '--configuration $(buildConfiguration)' | |
projects: '$(System.DefaultWorkingDirectory)/**/*UITests.csproj' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Run UI tests - $(buildConfiguration)' | |
inputs: | |
command: 'test' | |
arguments: '--no-build --configuration $(buildConfiguration)' | |
publishTestResults: true | |
projects: '$(System.DefaultWorkingDirectory)/**/*UITests.csproj' | |
testRunTitle: 'UI Tests' | |
- stage: 'Staging' | |
displayName: 'Deploy to the staging environment' | |
dependsOn: Test | |
condition: and(succeeded('Test'), eq(variables['build.sourceBranch'], 'refs/heads/master')) | |
jobs: | |
- deployment: Deploy | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
environment: staging | |
variables: | |
- group: 'Release' | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: drop | |
- task: AzureWebApp@1 | |
displayName: 'Azure App Service Deploy: website' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
appName: '$(appName)-$(System.StageName)-$(appID)' | |
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip' | |
- task: AzureCLI@2 | |
displayName: 'Set connection string' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az webapp config connection-string set --name $(appName)-$(System.StageName)-$(appID) --resource-group $(serviceConnection) --connection-string-type SQLAzure --settings "DefaultConnection=Server=tcp:$(servername).database.windows.net,1433;Initial Catalog=$(databasename);Persist Security Info=False;User ID=$(adminlogin);Password=$(adminPassword);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | |
- job: RunLoadTests | |
dependsOn: Deploy | |
displayName: 'Run load tests' | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
variables: | |
jmeterVersion: '5.2' | |
steps: | |
- script: | | |
wget -c ftp.ps.pl/pub/apache/jmeter/binaries/apache-jmeter-$(jmeterVersion).tgz | |
tar -xf apache-jmeter-$(jmeterVersion).tgz | |
displayName: 'Install Apache JMeter' | |
- script: apache-jmeter-$(jmeterVersion)/bin/./jmeter -n -t LoadTest.jmx -o Results.xml -Jhostname=$(STAGING_HOSTNAME) | |
displayName: 'Run Load tests' | |
- script: | | |
sudo apt-get update | |
sudo apt-get install xsltproc | |
xsltproc JMeter2JUnit.xsl Results.xml > JUnit.xml | |
displayName: 'Transform JMeter output to JUnit' | |
- task: PublishTestResults@2 | |
inputs: | |
testResultsFormat: JUnit | |
testResultsFiles: JUnit.xml | |
testRunTitle: 'Load Tests' | |
- stage: 'Prod' | |
displayName: 'Deploy to the Production environment' | |
dependsOn: Staging | |
condition: and(succeeded('Staging'), eq(variables['build.sourceBranch'], 'refs/heads/master')) | |
jobs: | |
- deployment: Deploy | |
pool: | |
vmImage: 'Ubuntu-16.04' | |
environment: prod | |
variables: | |
- name: serviceConnection | |
value: 'tailspin-space-game-prod-rg' | |
- group: 'Release' | |
strategy: | |
runOnce: | |
deploy: | |
steps: | |
- download: current | |
artifact: drop | |
- task: AzureWebApp@1 | |
displayName: 'Azure App Service Deploy: website' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
appName: '$(appName)-$(System.StageName)-$(appID)' | |
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip' | |
- task: AzureCLI@2 | |
displayName: 'Set connection string' | |
inputs: | |
azureSubscription: '$(serviceConnection)' | |
scriptType: 'bash' | |
scriptLocation: 'inlineScript' | |
inlineScript: | | |
az webapp config connection-string set --name $(appName)-$(System.StageName)-$(appID) --resource-group $(serviceConnection) --connection-string-type SQLAzure --settings "DefaultConnection=Server=tcp:$(servername).database.windows.net,1433;Initial Catalog=$(databasename);Persist Security Info=False;User ID=$(adminlogin);Password=$(adminPassword);MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" | |
- job: RunUITests | |
dependsOn: Deploy | |
displayName: 'Run UI tests' | |
pool: | |
vmImage: 'windows-2019' | |
variables: | |
- group: 'Release' | |
steps: | |
- task: DotNetCoreInstaller@0 | |
displayName: 'Use .NET Core SDK $(dotnetSdkVersion)' | |
inputs: | |
version: '$(dotnetSdkVersion)' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Build the project - $(buildConfiguration)' | |
inputs: | |
command: 'build' | |
arguments: '--configuration $(buildConfiguration)' | |
projects: '$(System.DefaultWorkingDirectory)/**/*UITests.csproj' | |
- task: DotNetCoreCLI@2 | |
displayName: 'Run UI tests - $(buildConfiguration)' | |
inputs: | |
command: 'test' | |
arguments: '--no-build --configuration $(buildConfiguration)' | |
publishTestResults: true | |
projects: '$(System.DefaultWorkingDirectory)/**/*UITests.csproj' | |
testRunTitle: 'UI Tests' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment