-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
188 lines (184 loc) · 4.63 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
library "aplazame-shared-library"
pipeline {
agent {
kubernetes {
yamlFile "/jenkins/php.yaml"
}
}
environment {
FOLDER = "dist"
foldersCache = '"vendor/"'
}
options {
disableConcurrentBuilds()
ansiColor('xterm')
}
stages {
stage('Test Sonarqube') {
when {
not {
tag "*"
}
}
agent {
kubernetes {
yamlFile "/jenkins/jenkins-sonar.yaml"
}
}
environment {
SONAR_TEST = credentials('SONAR_TEST')
CODE_SOURCE_DEFAULT = "aplazame"
}
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/prestashop/${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/prestashop/${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/prestashop/${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/prestashop/
"""
}
}
}
stage("Create Release") {
when {
branch 'master'
}
environment {
GITHUB_TOKEN = credentials('gh-releases-token-old')
}
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: 'Create release for pro?', ok: 'Yes'
}
}
container('php') {
sh """
echo "***************Create Release***************"
export APP_VERSION="\$(cat Makefile | grep version | cut -d '=' -f2)"
echo \$APP_VERSION
gh release create \$APP_VERSION --notes "Release created by Jenkins.<br />Build: $BUILD_TAG;$BUILD_URL>"
"""
}
}
}
}
}