-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
254 lines (251 loc) · 7.03 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
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
library "aplazame-shared-library"
deployToPro = false
pipeline {
agent {
kubernetes {
yamlFile "/jenkins/php.yaml"
}
}
environment {
FOLDER = "dist"
foldersCache = '"vendor/"'
GITHUB_TOKEN = credentials('gh-releases-token-old')
}
options {
disableConcurrentBuilds()
ansiColor('xterm')
}
stages {
stage('Test Sonarqube') {
when {
not {
tag "*"
}
}
agent {
kubernetes {
yamlFile "/jenkins/jenkins-sonar.yaml"
}
}
environment {
SONAR_TEST = credentials('SONAR_TEST')
WORDPRESS_USERNAME = credentials('WORDPRESS_USERNAME')
WORDPRESS_PASSWORD = credentials('WORDPRESS_PASSWORD')
CODE_SOURCE_DEFAULT = "plugin"
GITHUB_TOKEN = credentials('gh-releases-token-old')
}
steps {
scmSkip()
container('sonar') {
sonarScan(SONAR_TEST,CODE_SOURCE_DEFAULT)
}
}
}
stage("Get cache") {
when {
not {
tag "*"
}
}
steps {
script {
HASH = sh(script: 'md5sum composer.json | awk \'{print \$1}\'', returnStdout: true).trim()
CACHE_KEY = 'v1-dependencies-' + HASH
container('php') {
sh """
load-config
export AWS_PROFILE=AplazameSharedServices
set -e
aws s3 cp --quiet s3://aplazameshared-jenkins-cache/Aplazame-Backend/woocommerce/${CACHE_KEY} cache.tar.gz || exit 0
[ -f cache.tar.gz ] && tar -xf cache.tar.gz
"""
//loadCache(CACHE_KEY)
}
}
}
}
stage("Composer Install") {
when {
not {
tag "*"
}
}
steps {
container('php') {
sh """
composer install -n --prefer-dist
"""
}
}
}
stage("Upload Cache") {
when {
not {
tag "*"
}
}
steps {
container('php') {
sh """
load-config
export AWS_PROFILE=AplazameSharedServices
set -e
MATCHES=\$(aws s3 ls s3://aplazameshared-jenkins-cache/Aplazame-Backend/woocommerce/${CACHE_KEY} | wc -l)
[ "\$MATCHES" = "0" ] && [ ! -f cache.tar.gz ] && tar -czf cache.tar.gz vendor/ && aws s3 cp --quiet cache.tar.gz s3://aplazameshared-jenkins-cache/Aplazame-Backend/woocommerce/${CACHE_KEY}
exit 0
"""
//saveCache(CACHE_KEY,["${foldersCache}"])
}
}
}
stage("Check Syntax") {
when {
not {
tag "*"
}
}
steps {
container('php') {
sh """
make syntax.checker
"""
}
}
}
stage("CS Style") {
when {
not {
tag "*"
}
}
steps {
container('php') {
sh """
make style
"""
}
}
}
stage("Create bundle") {
when {
branch 'master'
}
steps {
container('php') {
sh """
make zip
"""
}
}
}
stage("Deploy to S3") {
when {
branch 'master'
}
steps {
scmSkip()
timeout(time: 15, unit: "MINUTES") {
script {
slackSend failOnError: true, color: '#8000FF', channel: '#backend-pipelines', message: "You need :hand: intervention in ${currentBuild.fullDisplayName} (<${env.BUILD_URL}console|Open here>)", username: "Jenkins CI"
input id: 'ReleaseApproval', message: 'Deploy to S3?', ok: 'Yes'
}
}
container('php') {
sh """
echo "Deploy to S3"
load-config
export AWS_PROFILE=Aplazame
aws s3 cp --acl public-read aplazame.latest.zip s3://aplazame/modules/woocommerce/
"""
}
}
}
stage('Deploy to Wordpress and Create Release') {
when {
branch 'master'
}
steps {
script {
try {
timeout(time: 10, unit: "MINUTES") {
slackSend failOnError: true, color: '#8000FF', channel: '#backend-pipelines', message: "You need :hand: intervention in ${currentBuild.fullDisplayName} (<${env.BUILD_URL}console|Open here>)", username: "Jenkins CI"
deployToPro = input(id: 'deployToPro', message: 'Deploy to Wordpress and Creatate Tag?',
parameters: [
booleanParam(name: 'deploy', description: 'Deploy to Wordpress and Creatate Tag?', defaultValue: false)
])
}
} catch (err) {
currentBuild.result = "SUCCESS"
}
}
}
}
stage("Create Release") {
when {
beforeAgent true
allOf {
expression { deployToPro }
branch 'master'
}
}
steps {
container('php') {
sh """
echo "***************Create Release***************"
export APP_VERSION="\$(cat Makefile | grep 'version ?=' | cut -d '=' -f2 | cut -c2-)"
echo \$APP_VERSION
echo "\$APP_VERSION" > APP_VERSION.tmp
gh release create \$APP_VERSION --notes "Release created by Jenkins.<br />Build: $BUILD_TAG;$BUILD_URL>"
"""
}
}
}
stage("Deploy to Wordpress") {
when {
beforeAgent true
allOf {
expression { deployToPro }
branch 'master'
}
}
environment {
WORDPRESS_USERNAME = credentials('WORDPRESS_USERNAME')
WORDPRESS_PASSWORD = credentials('WORDPRESS_PASSWORD')
}
steps {
container('php') {
sh """
echo "***************Clone wordpress repository***************"
svn co https://plugins.svn.wordpress.org/aplazame svn
"""
sh """
echo "****************Sync assets******************************"
rsync -r -p --delete assets/ svn/assets
svn add --force svn/assets
"""
sh """
echo "****************Sync trunk******************************"
rsync -r -p --delete plugin/ svn/trunk
svn add --force svn/trunk
"""
sh """
echo "****************Delete unused files******************************"
for i in \$(svn status svn | grep \\! | awk '{print \$2}'); do svn delete \$i; done
"""
sh """
echo "****************Tag Release******************************"
export APP_VERSION="\$(cat APP_VERSION.tmp)"
echo \$APP_VERSION
svn cp svn/trunk svn/tags/\$APP_VERSION
"""
sh """
echo "****************Commit to Wordpress******************************"
export APP_VERSION="\$(cat APP_VERSION.tmp)"
echo \$APP_VERSION
svn ci --no-auth-cache --username ${WORDPRESS_USERNAME} --password ${WORDPRESS_PASSWORD} svn -m "tagging version \$APP_VERSION"
"""
}
}
}
}
}