-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile
102 lines (98 loc) · 4.17 KB
/
Jenkinsfile
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
node {
// Clean workspace before doing anything
deleteDir()
MAGENTO_DIR='magento'
try {
stage ('Clone') {
checkout scm
}
stage ('Install') {
sh "composer install"
}
stage ('Tests') {
sh "bin/mg2-builder tests-setup:install -Dproject.name=${BRANCH_NAME} -Ddatabase.admin.username=${DATABASE_USER} -Ddatabase.admin.password=${DATABASE_PASS} -Ddatabase.user=${DATABASE_USER} -Ddatabase.password=${DATABASE_PASS} -DskipDbUserCreation"
parallel 'static': {
sh "grumphp run"
},
'unit': {
sh "cd ${MAGENTO_DIR}/dev/tests/unit && ../../../../bin/phpunit -c phpunit.xml"
},
'integration': {
sh "cd ${MAGENTO_DIR}/dev/tests/integration && ../../../../bin/phpunit -c phpunit.xml"
},
failFast: true
}
branchInfo = getBranchInfo()
if (branchInfo.type == 'develop') {
stage ('Artifact') {
sh "bin/mg2-builder artifact:transfer -Dartifact.name=${branchInfo.version} -Dremote.environment=igr -Duse.server.properties"
}
stage ('Deploy DEV') {
sh "bin/mg2-builder release:deploy -Dremote.environment=igr -Drelease.version=${branchInfo.version} -Ddeploy.build.type=artifact"
}
}
if (branchInfo.type == 'release' || branchInfo.type == 'hotfix') {
stage ('Confirm Deploy') {
confirmedServer = confirmServerToDeploy()
}
if (confirmedServer) {
stage ('TAG VERSION') {
sh "git remote set-branches --add origin master && git remote set-branches --add origin develop && git fetch"
sh "git checkout master && git checkout develop && git checkout ${BRANCH_NAME}"
sh "git flow init -d"
sh "bin/mg2-builder release:finish -Drelease.type=${branchInfo.type} -Drelease.version=${branchInfo.version}"
}
if (confirmedServer in ['stage','both']) {
stage ('Artifact') {
sh "bin/mg2-builder artifact:transfer -Dartifact.name=${branchInfo.version} -Dremote.environment=stage -Duse.server.properties"
}
stage ('Deploy STAGE') {
sh "bin/mg2-builder release:deploy -Dremote.environment=stage -Drelease.version=${branchInfo.version} -Ddeploy.build.type=artifact"
}
}
if (confirmedServer in ['production','both']) {
stage ('Artifact') {
sh "bin/mg2-builder artifact:transfer -Dartifact.name=${branchInfo.version} -Dremote.environment=prod -Duse.server.properties"
}
stage ('Deploy PROD') {
sh "bin/mg2-builder release:deploy -Dremote.environment=prod -Drelease.version=${branchInfo.version} -Ddeploy.build.type=artifact"
}
}
}
}
stage ('Clean Up') {
sh "bin/mg2-builder util:db:clean -Dproject.name=${BRANCH_NAME} -Ddatabase.admin.username=${DATABASE_USER} -Ddatabase.admin.password=${DATABASE_PASS}"
deleteDir()
}
} catch (err) {
currentBuild.result = 'FAILED'
// Send email or another notification
throw err
}
}
def getBranchInfo() {
def branchInfo = [:]
branchData = BRANCH_NAME.split('/')
if (branchData.size() == 2) {
branchInfo['type'] = branchData[0]
branchInfo['version'] = branchData[1]
} else {
branchInfo['type'] = BRANCH_NAME
branchInfo['version'] = BRANCH_NAME
}
return branchInfo
}
def confirmServerToDeploy() {
def server = false
try {
timeout(time:2, unit:'HOURS') {
server = input(
id: 'environmentInput', message: 'Deployment Settings', parameters: [
choice(choices: "stage\nproduction\nboth", description: 'Target server to deploy', name: 'deployServer')
])
}
} catch (err) {
echo "Timeout expired. Environment was not set by user"
}
return server
}