This repository was archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure-pipelines.yml
147 lines (138 loc) · 4.96 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
name: $(BuildId)
trigger:
batch: false
branches:
include:
- '*'
tags:
include:
- '*'
pool:
vmImage: 'ubuntu-latest'
pr:
autoCancel: true
branches:
include:
- '*'
variables:
ARTIFACT_NAME: drop
REVIEW_APP_NAME_ROOT: 'nhsuk-cache-flush-func-dev-uks-PR-'
VAULT_APP_NAME: 'nhsuk.cache-flush'
KEYVAULT_NAME: 'nhsukcacheflush'
SUBSCRIPTION_NAME: 'Nhsuk.cache-flush'
stages:
- stage: build
jobs:
- job: RunTests
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --output ./bin
fi
displayName: 'build function extensions'
- script: npm install
displayName: 'npm install'
- script: npm run lint
displayName: 'npm run lint'
- script: npm run test-with-coverage
displayName: 'npm run test-with-coverage'
- script: npm prune --production
displayName: 'npm prune --production'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
reportDirectory: '$(System.DefaultWorkingDirectory)/coverage'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: '$(System.DefaultWorkingDirectory)/test-results.xml'
testRunner: JUnit
- task: ArchiveFiles@2
displayName: 'Archive Function App'
inputs:
archiveFile: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
includeRootFolder: false
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts'
inputs:
artifactName: $(ARTIFACT_NAME)
pathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
- stage: deployReviewEnvironment
displayName: 'Deploy to Review Environment'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/pull/'), eq(variables['Build.Reason'], 'PullRequest'))
dependsOn: build
jobs:
- template: ./templates/deployment-job.yml
parameters:
appName: '$(REVIEW_APP_NAME_ROOT)$(System.PullRequest.pullRequestNumber)'
appTest: deployed
azureSubscription: '$(SUBSCRIPTION_NAME)-dev'
environment: cacheflush-review
releaseEnvironment: dev
keyVault: '$(KEYVAULT_NAME)devuks'
- stage: deployIntegrationEnvironment
displayName: 'Deploy to Integration Environment'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
dependsOn: build
jobs:
- template: ./templates/deployment-job.yml
parameters:
appName: 'nhsuk-cache-flush-func-int-uks'
appTest: running
azureSubscription: '$(SUBSCRIPTION_NAME)-prod'
environment: cacheflush-int
releaseEnvironment: int
keyVault: '$(KEYVAULT_NAME)produks'
- job: getNumberForMergedPR
displayName: Get the number of the merged PR
steps:
- bash: $(System.DefaultWorkingDirectory)/scripts/get-pr-number.sh "$BUILD_SOURCEVERSIONMESSAGE"
displayName: 'Set PR number, if available'
name: PR_NUMBER
- job: deleteReviewEnvironment
condition: gt(dependencies.getNumberForMergedPR.outputs['PR_NUMBER.PR_NUMBER'], 0)
dependsOn: getNumberForMergedPR
displayName: Delete review environment for merged PR
variables:
PR_NUMBER: $[dependencies.getNumberForMergedPR.outputs['PR_NUMBER.PR_NUMBER']]
RESOURCE_GROUP: nhsuk-utils-rg-dev-uks
REVIEW_APP_NAME: $(REVIEW_APP_NAME_ROOT)$(PR_NUMBER)
steps:
- task: AzureCLI@2
displayName: 'Delete review environment func app and app insights for merged PR'
inputs:
azureSubscription: '$(SUBSCRIPTION_NAME)-dev'
inlineScript: |
az extension add --name application-insights
az monitor app-insights component delete --resource-group $(RESOURCE_GROUP) --app $(REVIEW_APP_NAME) --debug
az functionapp delete --resource-group $(RESOURCE_GROUP) --name $(REVIEW_APP_NAME) --debug
scriptLocation: inlineScript
scriptType: bash
- stage: deployStagingEnvironment
displayName: 'Deploy to Staging Environment'
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
dependsOn: build
jobs:
- template: ./templates/deployment-job.yml
parameters:
appName: 'nhsuk-cache-flush-func-stag-uks'
appTest: running
azureSubscription: '$(SUBSCRIPTION_NAME)-prod'
environment: cacheflush-staging
releaseEnvironment: staging
keyVault: '$(KEYVAULT_NAME)produks'
- stage: deployProductionEnvironment
displayName: 'Deploy to Production Environment'
dependsOn: deployStagingEnvironment
jobs:
- template: ./templates/deployment-job.yml
parameters:
appName: 'nhsuk-cache-flush-func-prod-uks'
appTest: running
azureSubscription: '$(SUBSCRIPTION_NAME)-prod'
environment: cacheflush-production
releaseEnvironment: production
keyVault: '$(KEYVAULT_NAME)produks'