forked from VirtoCommerce/jenkins-pipeline-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQAEnv
326 lines (307 loc) · 16.8 KB
/
QAEnv
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import groovy.json.JsonSlurperClassic
import jobs.scripts.*
def SETTINGS
def TRG_BRANCH
def SRC_BRANCH
def DELIVERY_AZURE = false
def DOCKER_SQL_PORT
def DOCKER_PLATFORM_PORT
def DOCKER_STOREFRONT_PORT
def PLATFORM_DOCKER_TAG
def STOREFRONT_DOCKER_TAG
def STOREFRONT_BRANCH
def STOREFRONT_INSTALL
def UNSTABLE_CAUSES = []
pipeline
{
agent any
options
{
timestamps()
}
stages
{
stage("User Input")
{
steps
{
script
{
checkout scm
// configFileProvider([configFile(fileId: 'qaenv', variable: 'SETTINGS_FILE')]) {
// SETTINGS = Settings.new(readFile(SETTINGS_FILE))
// }
// SETTINGS.setProject("qaenv")
// SETTINGS.setBranch("master")
// def branches = Utilities.getSubfolders("${env.SOLUTION_FOLDER}\\${SETTINGS['prefix']}").join("\n")
// def userInput = input message: "Select Branch", parameters:
// [
// choice(name:'Source Branch', choices:SETTINGS['sourceBranches']),
// choice(name:'Target Branch', choices:branches),
// booleanParam(defaultValue: false, name: 'Delviery to Azure')
// ]
// SRC_BRANCH = userInput["Source Branch"]
// TRG_BRANCH = userInput["Target Branch"]
// DELIVERY_AZURE = userInput["Delivery to Azure"]
// echo "Source Branch: ${SRC_BRANCH}; Target Branch: ${TRG_BRANCH};"
def settingsFileContent
configFileProvider([configFile(fileId: 'delivery_settings', variable: 'SETTINGS_FILE')]) {
settingsFileContent = readFile(SETTINGS_FILE)
}
SETTINGS = new Settings(settingsFileContent)
def regionChoices = SETTINGS.getProjects().join("\n")
def buildOrder = Utilities.getNextBuildOrder(this)
def userInputRegion = input message: "Select Region", parameters: [
choice(name: 'Region', choices: regionChoices)
]
PROJECT_TYPE = 'SOLUTION'
REGION = userInputRegion
UPDATE_CS = true
SETTINGS.setProject(REGION)
def envChoices = SETTINGS.getBranches().join("\n")
def userEnvInput = input message: "Select Environment", parameters: [
choice(name: 'Environments', choices: envChoices)
]
ENV_NAME = userEnvInput
SETTINGS.setBranch(ENV_NAME)
def srcBranches = SETTINGS['branch'] as String[]
def targetBranches = Utilities.getSubfolders("${env.SOLUTION_FOLDER}\\vc").join("\n")
def userInputBranch = input message: "Select Branch and docker state", parameters: [
booleanParam(defaultValue: true, name: 'Disable docker'),
choice(name:'Source Branch', choices:srcBranches.join("\n")),
choice(name:'Target Branch', choices:targetBranches),
string(name: 'Storefront Branch', defaultValue:SETTINGS['storefrontBranch'])
]
DELIVERY_AZURE = userInputBranch['Disable docker']
SRC_BRANCH = userInputBranch['Source Branch']
TRG_BRANCH = userInputBranch['Target Branch']
STOREFRONT_BRANCH = userInputBranch['Storefront Branch']
echo "Vars: REGION - ${REGION}, DELIVERY_AZURE - ${DELIVERY_AZURE}, ENV_NAME - ${ENV_NAME}, SRC_BRANCH - ${SRC_BRANCH}, TRG_BRANCH - ${TRG_BRANCH}"
}
}
}
stage("Preparing Solution"){
steps
{
script
{
def csSrc = "${env.SOLUTION_FOLDER}\\${SETTINGS['prefix']}\\${SRC_BRANCH}"
def csTarget = "${env.SOLUTION_FOLDER}\\${SETTINGS['prefix']}\\${TRG_BRANCH}"
def modulesRoot = "${env.WORKSPACE}\\CS\\module"
powershell script: "Remove-Item -Path ${env.WORKSPACE}\\CS\\* -Recurse -Force -ErrorAction Continue", label: "Clean Workspace"
powershell script: "Copy-Item -Path ${csSrc}\\* -Destination ${env.WORKSPACE}\\CS -Recurse -Force", label: "Copy Solution to Workspace"
if(SRC_BRANCH == 'support_2.x' || SRC_BRANCH == 'support_2.x-dev' || SRC_BRANCH == 'dev' || SRC_BRANCH == 'master')
{
def solutionRoot = "${env.SOLUTION_FOLDER}\\${SETTINGS['prefix']}"
//theme
def themeIncludeParam = ''
def themeSrc = "${solutionRoot}\\${SETTINGS['themeBranch']}\\theme"
def themeTargetBranchExists = new File("${solutionRoot}\\${TRG_BRANCH}\\theme").exists()
if(themeTargetBranchExists)
{
themeSrc = "${solutionRoot}\\${TRG_BRANCH}\\theme"
}
def themeDst = "${env.WORKSPACE}\\CS\\theme"
if(SETTINGS['themeName'] != '' && SETTINGS['themeName'] != null)
{
themeIncludeParam = "-Include ${SETTINGS['themeName'].join(',')}"
}
powershell script: "New-Item -Path ${themeDst} -ItemType Directory -Force"
powershell script: "Copy-Item -Path ${themeSrc}\\* ${themeIncludeParam} -Destination ${themeDst} -Recurse -Force", label: "Copy Theme to Workspace"
//storefront
def storefrontSrc = "${solutionRoot}\\${STOREFRONT_BRANCH}"
powershell script: "Copy-Item -Path ${storefrontSrc}\\* -Destination ${env.WORKSPACE}\\CS -Include storefront -Recurse -Force", label: "Copy Storefron to Workspace"
}
else {
def themeTargetBranchExists = new File("${csTarget}\\theme").exists()
powershell "Copy-Item -Path ${themeTargetBranchExists ? csTarget : csSrc}\\theme -Destination ${env.WORKSPACE}\\CS -Recurse -Force"
if(new File("${csTarget}\\storefront").exists())
{
STOREFRONT_INSTALL = true
powershell "Copy-Item -Path ${csTarget}\\storefront -Destination ${env.WORKSPACE}\\CS -Recurse -Force"
}
}
dir(modulesRoot)
{
powershell "Get-ChildItem ${csTarget}\\module -Name | Remove-Item -ErrorAction SilentlyContinue -Force -Recurse"
}
powershell "Copy-Item -Path ${csTarget}\\* -Destination ${env.WORKSPACE}\\CS -Recurse -Force"
powershell "Remove-Item ${env.WORKSPACE}\\CS\\modules -ErrorAction Ignore -Recurse -Force"
powershell "Rename-Item -Path ${modulesRoot} -NewName modules"
}
}
}
stage("Docker Environment")
{
steps
{
script
{
if(!DELIVERY_AZURE)
{
stage('Create Test Environment')
{
timestamps
{
DOCKER_SQL_PORT = Utilities.getSqlPort(this)
DOCKER_PLATFORM_PORT = Utilities.getPlatformPort(this)
DOCKER_STOREFRONT_PORT = Utilities.getStorefrontPort(this)
switch(SRC_BRANCH)
{
case 'dev':
PLATFORM_DOCKER_TAG = '3.0-dev'
STOREFRONT_DOCKER_TAG = '3.0-dev'
break
case 'master':
PLATFORM_DOCKER_TAG = 'latest-win'
STOREFRONT_DOCKER_TAG = 'latest-win'
break
}
// Start docker environment
dir(Utilities.getComposeFolderV3(this))
{
echo "PLATFORM_DOCKER_TAG=${PLATFORM_DOCKER_TAG}, STOREFRONT_DOCKER_TAG=${STOREFRONT_DOCKER_TAG}, 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(["PLATFORM_DOCKER_TAG=${PLATFORM_DOCKER_TAG}", "STOREFRONT_DOCKER_TAG=${STOREFRONT_DOCKER_TAG}", "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 up -d"
}
}
}
}
stage('Install Modules')
{
timestamps
{
def platformContainer = Utilities.getPlatformContainer(this)
def platformHost = Utilities.getPlatformCoreHost(this)
sleep 30
// install modules
Utilities.runPS(this, 'docker_v3/setup-modulesFromDir.ps1', "-PlatformContainer ${platformContainer} -ModulesDir ${env.WORKSPACE}\\CS\\modules -Verbose -Debug")
Utilities.runPS(this, "docker_v3/vc-check-installed-modules.ps1", "-ApiUrl ${platformHost} -Verbose -Debug")
}
}
stage('Install Sample Data')
{
timestamps
{
Utilities.runPS(this, "docker_v3/vc-setup-sampledata.ps1", "-ApiUrl ${Utilities.getPlatformCoreHost(this)} -Verbose -Debug")
}
}
stage('Storefront Install')
{
timestamps
{
if(STOREFRONT_INSTALL)
{
def storefrontContainer = Utilities.getStorefrontContainer(this)
def storefrontDir = "${env.WORKSPACE}\\CS\\storefront"
//bat "docker exec ${storefrontContainer} cmd /c \"rmdir /S /Q C:\\vc-storefront\""
bat "docker stop ${storefrontContainer}"
bat "docker cp ${storefrontDir} ${storefrontContainer}:/vc-storefront/."
bat "docker start ${storefrontContainer}"
}
}
}
stage('Theme Install')
{
timestamps
{
// //def storefrontContainer = Utilities.getStorefrontContainer(this)
// def platformContainer = Utilities.getPlatformContainer(this)
// def themeFolder = "${env.WORKSPACE}\\CS\\theme"
// //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/Themes"
// bat "docker exec ${platformContainer} powershell -Command \"Copy-Item -Path C:\\tmp\\Themes -Destination C:\\vc-platform\\App_Data\\cms-content\\Themes -Recurse -Force\""
Utilities.runPS(this, "docker_v3/vc-theme-install.ps1", "-ThemePath ${env.WORKSPACE}\\CS\\theme -StorefrontContainer ${Utilities.getStorefrontContainer(this)}")
}
}
stage('Awaiting Proceed')
{
timestamps
{
def platformPort = (Utilities.getPlatformPort(this) as int) - 1000
def storefrontPort = (Utilities.getStorefrontPort(this) as int) - 1000
def msg = "Storefront:\nhttps://docker.virtocommerce.com:${storefrontPort}\nPlatform:\nhttps://docker.virtocommerce.com:${platformPort}"
input message: msg
}
}
}
else
{
stage('Create Test Environment'){timestamps{}}
stage('Install Modules'){timestamps{}}
stage('Install Sample Data'){timestamps{}}
stage('Storefront Install'){timestamps{}}
stage('Theme Install'){timestamps{}}
stage('Awaiting Proceed'){timestamps{}}
}
}
}
}
stage("Create / Update Environment"){
when {
expression {
UPDATE_CS
}
}
steps {
script{
def resourceGroupName = SETTINGS['resourceGroupName']
Utilities.createInfrastructure(this, "${resourceGroupName}")
}
}
}
stage("Update Solution"){
when {
expression {
UPDATE_CS
}
}
steps {
script{
def csRoot = "${env.WORKSPACE}\\CS"
def webAppName = SETTINGS['webAppName'].join(',')
def webAppPublicName = SETTINGS['webAppPublicName']
def resourceGroupName = SETTINGS['resourceGroupName']
def subscriptionID = SETTINGS['subscriptionID']
def blobToken = SETTINGS['blobToken']
def themeSrcDir = "${csRoot}\\theme"
def themeBlobPath = ""
def themeBlobPathParam = ""
withEnv(["AzureBlobToken=${blobToken}"]){
Utilities.runSharedPS(this, 'delivery/upload-CS.ps1',
"-PlatformDir ${csRoot}\\platform -ModulesDir ${csRoot}\\modules -StorefrontDir ${csRoot}\\storefront -ThemeDir ${themeSrcDir} -WebAppName ${webAppName} -WebAppPublicName ${webAppPublicName} -ResourceGroupName ${resourceGroupName} -SubscriptionID ${subscriptionID} -StorageAccount ${SETTINGS['storageAccount']} -BlobContainerName ${SETTINGS['blobContainerName']} ${themeBlobPathParam}")
}
}
}
}
}
post
{
always
{
script
{
if(currentBuild.resultIsBetterOrEqualTo('SUCCESS') && UNSTABLE_CAUSES.size()>0){
currentBuild.result = 'UNSTABLE'
for(cause in UNSTABLE_CAUSES){
echo cause
}
}
dir(Utilities.getComposeFolderV3(this))
{
withEnv(["PLATFORM_DOCKER_TAG=${PLATFORM_DOCKER_TAG}", "STOREFRONT_DOCKER_TAG=${STOREFRONT_DOCKER_TAG}", "DOCKER_PLATFORM_PORT=${DOCKER_PLATFORM_PORT}", "DOCKER_STOREFRONT_PORT=${DOCKER_STOREFRONT_PORT}", "DOCKER_SQL_PORT=${DOCKER_SQL_PORT}", "COMPOSE_PROJECT_NAME=${env.BUILD_TAG}"]){
if(!DELIVERY_AZURE){
bat "docker-compose down -v"
}
}
}
}
}
}
}