-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvc_slv
307 lines (280 loc) · 13.6 KB
/
vc_slv
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import jobs.scripts.*
import groovy.json.JsonSlurperClassic
def SETTINGS
def BRANCH_NAME
def BASE_BRANCH
def DELIVERY_AZURE = true
def STOREFRONT_VERSION = ''
def THEME_VERSION = ''
def DOCKER_SQL_PORT
def DOCKER_PLATFORM_PORT
def DOCKER_STOREFRONT_PORT
def DOCKER_PREFIX
def DOCKER_TAG
def PLATFORM_INSTALL = true
def STOREFRONT_INSTALL = true
def backendPath
def deployScript = 'VC-2AzureDEV.ps1'
pipeline
{
agent any
//agent {label 'slave'}
options
{
timestamps()
}
stages
{
stage("User Input")
{
steps
{
script
{
deleteDir()
checkout scm
configFileProvider([configFile(fileId: 'virtocommerce', variable: 'SETTINGS_FILE')]) {
SETTINGS = new Settings(readFile(SETTINGS_FILE))
}
SETTINGS.setRegion("virtocommerce")
SETTINGS.setEnvironment("qa")
def branches = Utilities.getSubfolders("${env.SOLUTION_FOLDER}\\${SETTINGS['prefix']}").join("\n")
timeout(time: "${SETTINGS['timeoutMinutes']}", unit: 'MINUTES')
{
def userInput = input message: "Select Branch", parameters:
[
choice(name:'Start from', choices:SETTINGS['sourceBranches']),
choice(name:'Take Theme from', choices:branches),
booleanParam(defaultValue: true, name: 'Delviery to Azure')
]
BASE_BRANCH = userInput["Start from"]
BRANCH_NAME = userInput["Take Theme from"]
DELIVERY_AZURE = userInput["Delivery to Azure"]
echo "Start from: ${BASE_BRANCH}; Take Theme from: ${BRANCH_NAME};"
}
}
}
}
stage("Preparing Solution")
{
steps
{
script
{
backendPath = "${env.WORKSPACE}@tmp\\tmpBackend${env.BUILD_NUMBER}"
def appName = SETTINGS['appName']
//get backend
runPS("get-backend.ps1", "-AppName ${appName} -BackendPath ${backendPath} -ResourceGroupName \"${SETTINGS['resourceGroupName']}\" -SubscriptionID \"${SETTINGS['subscriptionID']}\"")
def platform_version = powershell script:"Write-Output \"\$([System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"${backendPath}\\platform\\bin\\VirtoCommerce.Platform.Web.dll\").FileVersion)\"", returnStdout: true
platform_version = platform_version.replace('.0', '').trim()
//get frontend
appName = SETTINGS['appNamePublic']
runPS("get-frontend.ps1", "-AppName ${appName} -BackendPath ${backendPath} -ResourceGroupName \"${SETTINGS['resourceGroupName']}\" -SubscriptionID \"${SETTINGS['subscriptionID']}\"")
//get theme
def repoOrg = "${SETTINGS['repoOrg']}"
def repoName = "${SETTINGS['prefix']}-content"
def tagContains = THEME_VERSION
def githubCredId = "${SETTINGS['githubCredentialsId']}"
echo "${repoOrg} and ${githubCredId}"
def themeFolder = SETTINGS['themeFolder']
dir("${themeFolder}")
{
deleteDir()
git branch: "${BRANCH_NAME}", credentialsId: "${githubCredId}", url: "https://github.com/${repoOrg}/${repoName}.git"
powershell "Copy-Item .\\theme .\\cms-content\\Themes\\vccom\\default -Recurse -Force"
powershell "Copy-Item .\\pages .\\cms-content\\Pages\\vccom -Recurse -Force"
}
}
}
}
// stage("Docker Environment")
// {
// steps
// {
// script
// {
// node(SETTINGS['agentLabel'])
// {
// stage('Create Test Environment')
// {
// timestamps
// {
// // Start docker environment
// def composeFolder = "${env.WORKSPACE}\\${SETTINGS['composeDir']}"
// dir(composeFolder)
// {
// DOCKER_SQL_PORT = Utilities.getSqlPort(this)
// DOCKER_PLATFORM_PORT = Utilities.getPlatformPort(this)
// DOCKER_STOREFRONT_PORT = Utilities.getStorefrontPort(this)
// DOCKER_PREFIX = 'vc'
// switch(BASE_BRANCH)
// {
// case 'dev':
// DOCKER_TAG = 'dev-branch'
// break
// case 'master':
// // DOCKER_TAG = 'latest'
// DOCKER_TAG = 'dev-branch'
// break
// }
// echo "DOCKER_PLATFORM_PORT=${DOCKER_PLATFORM_PORT}, DOCKER_STOREFRONT_PORT=${DOCKER_STOREFRONT_PORT}, DOCKER_SQL_PORT=${DOCKER_SQL_PORT}"
// // 1. stop containers
// // 2. remove instances including database
// // 3. start up new containers
// withEnv(["DOCKER_TAG=${DOCKER_TAG}", "DOCKER_PREFIX=${DOCKER_PREFIX}", "DOCKER_PLATFORM_PORT=${DOCKER_PLATFORM_PORT}", "DOCKER_STOREFRONT_PORT=${DOCKER_STOREFRONT_PORT}", "DOCKER_SQL_PORT=${DOCKER_SQL_PORT}", "COMPOSE_PROJECT_NAME=${env.BUILD_TAG}"])
// {
// // bat "docker-compose stop"
// // bat "docker-compose rm -f -v"
// bat "docker-compose up -d"
// }
// }
// }
// }
// stage('Install Platform')
// {
// timestamps
// {
// if(PLATFORM_INSTALL)
// {
// def platformContainer = Utilities.getPlatformContainer(this)
// def platformDir = "${backendPath}\\platform"
// bat "docker stop ${platformContainer}"
// bat "docker cp ${platformDir} ${platformContainer}:/vc-platform/."
// bat "docker start ${platformContainer}"
// }
// }
// }
// stage('Install Modules')
// {
// timestamps
// {
// def platformContainer = Utilities.getPlatformContainer(this)
// // install modules
// runPS('qaenv/install-modules.ps1', "-ApiUrl \"${Utilities.getPlatformHost(this)}\" -PlatformContainer ${platformContainer} -ModulesDir ${backendPath}\\modules")
// }
// }
// stage('Install Sample Data')
// {
// timestamps
// {
// def sampleDataSrcParam = ""
// if(SETTINGS['sampledata'] != null){
// sampleDataSrcParam = "-sampleDataSrc ${SETTINGS['sampledata']}"
// echo "using url from settings file"
// }
// runPS("vc-setup-sampledata.ps1", "-apiurl \"http://localhost:${DOCKER_PLATFORM_PORT}\" ${sampleDataSrcParam} -Verbose -Debug")
// }
// }
// stage('Install Storefront')
// {
// timestamps
// {
// if(STOREFRONT_INSTALL)
// {
// def storefrontContainer = Utilities.getStorefrontContainer(this)
// def storefrontDir = "${backendPath}\\storefront"
// bat "docker stop ${storefrontContainer}"
// bat "docker cp ${storefrontDir} ${storefrontContainer}:/vc-storefront/."
// bat "docker start ${storefrontContainer}"
// }
// }
// }
// stage('Install Theme')
// {
// timestamps
// {
// def platformContainer = Utilities.getPlatformContainer(this)
// def themeFolder = "${SETTINGS['themeFolder']}\\cms-content"
// // Utilities.runSharedPS(this, "vc-install-theme.ps1", "-themeZip \"${themeFolder}\" -platformContainer ${platformContainer}")
// // bat "docker exec ${platformContainer} powershell -Command \"Remove-Item C:\\vc-platform\\App_Data\\cms-content\\Themes -Recurse -Force\""
// bat "docker exec ${platformContainer} powershell -Command \"mkdir tmp\""
// bat "docker cp ${themeFolder} ${platformContainer}:/tmp"
// bat "docker exec ${platformContainer} powershell -Command \"Copy-Item -Path C:\\tmp\\cms-content\\* -Destination C:\\vc-platform\\App_Data\\cms-content -Recurse -Force\""
// }
// }
// stage('Awaiting Proceed')
// {
// timeout(time: "${SETTINGS['timeoutMinutes']}", unit: 'DAYS')
// {
// def message = "Platform url: ${SETTINGS["platformContainerUrl"]}:${DOCKER_PLATFORM_PORT}\nStorefront: ${SETTINGS["storefrontContainerUrl"]}:${DOCKER_STOREFRONT_PORT}"
// input(message)
// }
// }
// }
// }
// }
// }
stage('Delivery')
{
// when
// {
// expression
// {
// DELIVERY_AZURE
// }
// }
steps
{
script
{
def themeFolder = SETTINGS['themeFolder']
dir("${themeFolder}")
{
powershell "Copy-Item .\\pages ${env.WORKSPACE}\\pages -Recurse -Force"
powershell "Copy-Item .\\theme ${env.WORKSPACE}\\theme -Recurse -Force"
}
def stagingName = "qa"
def storeName = "cms-content"
def azureBlobName = SETTINGS['azureBlobName']
def azureBlobKey = SETTINGS['azureBlobKey']
def webAppName = SETTINGS['appNamePublic']
def resourceGroupName = SETTINGS['resourceGroupName']
def subscriptionID = SETTINGS['subscriptionID']
def blobToken = SETTINGS['tokenSas']
withEnv(["AzureBlobToken=${blobToken}"]){
def args = "-StagingName ${stagingName} -StoreName ${storeName} -AzureBlobName ${azureBlobName} -AzureBlobKey ${azureBlobKey} -WebAppName ${webAppName} -ResourceGroupName ${resourceGroupName} -SubscriptionID ${subscriptionID}"
runPS("${deployScript}", "${args}")
}
}
}
}
}
post
{
always
{
script
{
def composeFolder = "${env.WORKSPACE}\\${SETTINGS['composeDir']}"
dir(composeFolder)
{
withEnv(["DOCKER_TAG=${DOCKER_TAG}", "DOCKER_PREFIX=${DOCKER_PREFIX}", "DOCKER_PLATFORM_PORT=${DOCKER_PLATFORM_PORT}", "DOCKER_STOREFRONT_PORT=${DOCKER_STOREFRONT_PORT}", "DOCKER_SQL_PORT=${DOCKER_SQL_PORT}", "COMPOSE_PROJECT_NAME=${env.BUILD_TAG}"]){
echo "docker-compose down -v"
//bat "docker-compose down -v"
}
echo "docker image prune -f"
//bat "docker image prune -f"
}
}
}
}
}
def wakeUpNode(nodeLabel)
{
try
{
node(nodeLabel)
{
echo "${nodeLabel} is up!"
}
}
catch(any)
{
echo any.getMessage()
}
}
def runPS(psName, args)
{
def script = "${env.WORKSPACE}\\resources\\azure\\${psName} ${args} -ErrorAction Stop"
powershell script: script, label: "${psName} ${args}"
}