-
Notifications
You must be signed in to change notification settings - Fork 142
/
Jenkinsfile.realExample.groovy
116 lines (104 loc) · 3.87 KB
/
Jenkinsfile.realExample.groovy
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
node {
def PROJECT_NAME = "project_name"
// Clean workspace before doing anything
deleteDir()
propertiesData = [disableConcurrentBuilds()]
if (isValidDeployBranch()) {
propertiesData = propertiesData + parameters([
choice(choices: 'none\nIGR\nPRD', description: 'Target server to deploy', name: 'deployServer'),
])
}
properties(propertiesData)
try {
stage ('Clone') {
checkout scm
}
stage ('preparations') {
try {
deploySettings = getDeploySettings()
echo 'Deploy settings were set'
} catch(err) {
println(err.getMessage());
throw err
}
}
stage('Build') {
sh "mg2-builder install -Dproject.name=${PROJECT_NAME} -Dproject.environment=local -Dinstall.type=clean -Ddatabase.admin.username=${env.DATABASE_USER} -Ddatabase.admin.password=${env.DATABASE_PASS} -Denvironment.server.type=none"
}
stage ('Tests') {
parallel 'static': {
sh "bin/grumphp run --testsuite=magento2testsuite"
},
'unit': {
sh "magento/bin/magento dev:test:run unit"
},
'integration': {
sh "magento/bin/magento dev:test:run integration"
}
}
if (deploySettings) {
stage ('Deploy') {
if (deploySettings.type && deploySettings.version) {
// Deploy specific version to a specifc server (IGR or PRD)
sh "mg2-builder release:finish -Drelease.type=${deploySettings.type} -Drelease.version=${deploySettings.version}"
sh "ssh ${deploySettings.ssh} 'mg2-deployer release -Drelease.version=${deploySettings.version}'"
notifyDeployedVersion(deploySettings.version)
} else {
// Deploy to develop branch into IGR server
sh "ssh ${deploySettings.ssh} 'mg2-deployer release'"
}
}
}
} catch (err) {
currentBuild.result = 'FAILED'
notifyFailed()
throw err
}
}
def isValidDeployBranch() {
branchDetails = getBranchDetails()
if (branchDetails.type == 'hotfix' || branchDetails.type == 'release') {
return true
}
return false
}
def getBranchDetails() {
def branchDetails = [:]
branchData = BRANCH_NAME.split('/')
if (branchData.size() == 2) {
branchDetails['type'] = branchData[0]
branchDetails['version'] = branchData[1]
return branchDetails
}
return branchDetails
}
def getDeploySettings() {
def deploySettings = [:]
if (BRANCH_NAME == 'develop') {
deploySettings['ssh'] = "[email protected]"
} else if (params.deployServer && params.deployServer != 'none') {
branchDetails = getBranchDetails()
deploySettings['type'] = branchDetails.type
deploySettings['version'] = branchDetails.version
if (params.deployServer == 'PRD') {
deploySettings['ssh'] = "[email protected]"
} else if (params.deployServer == 'IGR') {
deploySettings['ssh'] = "[email protected]"
}
}
return deploySettings
}
def notifyDeployedVersion(String version) {
emailext (
subject: "Deployed: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: "DEPLOYED VERSION '${version}': Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]': Check console output at '${env.BUILD_URL}' [${env.BUILD_NUMBER}]",
to: "[email protected]"
)
}
def notifyFailed() {
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]': Check console output at '${env.BUILD_URL}' [${env.BUILD_NUMBER}]",
to: "[email protected]"
)
}