-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
214 lines (174 loc) · 4.35 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
pipeline {
agent {
label "jenkins-go"
}
environment {
ORG = 'kevinstl'
APP_NAME = 'lightning-kube'
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
}
stages {
stage('Determine Environment') {
steps {
script {
kubeEnv = sh(returnStdout: true, script: 'echo "${KUBE_ENV}"')
}
echo "kubeEnv: ${kubeEnv}"
}
}
stage('CI Build and push snapshot') {
when {
branch 'PR-*'
}
environment {
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
}
steps {
container('go') {
// sh "mvn versions:set -DnewVersion=$PREVIEW_VERSION"
//sh "mvn install"
//sh "./build.sh container prod verify"
// sh "./build.sh container prod package"
sh "make build"
sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml'
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
}
dir ('./charts/preview') {
container('go') {
sh "make preview"
sh "jx preview --app $APP_NAME --dir ../.."
}
}
}
}
stage('Build Release Feature') {
when {
branch 'feature-*'
}
steps {
script {
release(null)
}
}
}
stage('Build Release Master') {
when {
branch 'master'
}
steps {
script {
release('master')
}
}
}
stage('Promote to Environments Feature') {
when {
branch 'feature-*'
}
steps {
script {
if (kubeEnv?.trim() != 'local') {
promote()
}
}
}
}
stage('Promote to Environments Master') {
when {
branch 'master'
}
steps {
script {
if (kubeEnv?.trim() != 'local') {
promote()
}
}
}
}
stage('Deploy Local') {
steps {
script {
if (kubeEnv?.trim() == 'local') {
container('go') {
sh './undeploy-helm.sh "" || true'
sh './deploy-helm.sh "" jx-local \$(cat VERSION) lightning-kube-local NodePort 30801'
}
}
}
}
}
stage('Push Local') {
steps {
script {
if (kubeEnv?.trim() == 'local') {
container('go') {
sh "./push.sh"
}
}
}
}
}
}
post {
always {
cleanWs()
}
failure {
input """Pipeline failed.
We will keep the build pod around to help you diagnose any failures.
Select Proceed or Abort to terminate the build pod"""
}
}
}
def release(branch) {
container('go') {
// ensure we're not on a detached head
//sh "git checkout master"
if (branch?.trim()) {
sh "git checkout $branch"
}
sh "git config --global credential.helper store"
sh "jx step git credentials"
// so we can retrieve the version in later steps
sh "echo \$(jx-release-version) > VERSION"
// sh "mvn versions:set -DnewVersion=\$(cat VERSION)"
}
dir ('./charts/lightning-kube') {
if (kubeEnv?.trim() != 'local') {
container('go') {
sh "make tag"
}
}
}
container('go') {
//sh 'mvn clean deploy'
//sh "./build.sh container prod verify -DskipTests"
sh "ls -al"
//sh "./build.sh container prod package -DskipTests"
// sh "./build.sh container prod package"
sh "make build"
sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
// sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
postBuild()
}
}
def promote() {
dir ('./charts/lightning-kube') {
container('go') {
sh 'jx step changelog --version v\$(cat ../../VERSION)'
// release the helm chart
sh 'jx step helm release'
// promote through all 'Auto' promotion Environments
sh 'jx promote --verbose -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
}
}
}
def postBuild() {
script {
if (kubeEnv?.trim() != 'local') {
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
}
}
}