forked from redhat-cop/spring-rest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
232 lines (177 loc) · 7.56 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
pipeline {
agent any
parameters {
booleanParam(defaultValue: false,description: 'Deploy to Prod Environment ?', name: 'DEPLOY_PROD')
string(defaultValue: "0a4cc883-2d23-423c-ba2c-29f535162d0c", description: 'Maven Settings File Id', name: 'MAVEN_SETTINGS_ID')
string(defaultValue: "http://baifuseqa01.internal.com/nexus", description: 'Nexus URL', name: 'NEXUS_URL')
string(defaultValue: "artifacts", description: 'Nexus hosted repo name', name: 'NEXUS_HOSTED_NAME_RELEASES')
string(defaultValue: "artifacts-snapshots", description: 'Nexus hosted snapshots repo name', name: 'NEXUS_HOSTED_NAME_SNAPSHOTS')
string(defaultValue: '', name: 'EMAIL_RECIPIENT_LIST')
}
options {
// use colors in Jenkins console output
// ansiColor('xterm')
// discard old builds
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '45')
// disable concurrent builds and disable build resume
// disableConcurrentBuilds()
// disableResume()
// timeout on whole pipeline job
timeout(time: 1, unit: 'HOURS')
}
triggers {
pollSCM "*/2 * * * *"
}
environment {
PLACEHOLDER_VARIABLE = 'TBD'
}
stages {
stage("Initialize") {
agent any
steps {
script {
// notifyBuild('STARTED')
echo "Build number: ${BUILD_NUMBER} - Build id: ${env.BUILD_ID} on Jenkins instance: ${env.JENKINS_URL}"
echo "Deploy to QA? :: ${params.DEPLOY_QA}"
echo "Maven Settings file id? :: ${params.MAVEN_SETTINGS_ID}"
echo "NEXUS URL? :: ${params.NEXUS_URL}"
sh "printenv | sort"
}
}
}
stage('Code Build and Test') {
agent { label 'maven' }
steps {
configFileProvider([configFile(fileId: "${params.MAVEN_SETTINGS_ID}", variable: 'MAVEN_SETTINGS')]) {
sh "mvn -U -B clean package -s ${MAVEN_SETTINGS}"
// sh "./mvnw -U clean package -Pnexus-deploy -Dnexus.base.url=${NEXUS_URL} -Dnexus.hosted.name.releases=${NEXUS_HOSTED_NAME_RELEASES} -Dnexus.hosted.name.snapshots=${NEXUS_HOSTED_NAME_SNAPSHOTS} -s ${MAVEN_SETTINGS}"
}
// git url: "${SOURCE_CODE_URL}"
// sh "mvn -B clean install -q"
}
}
// stage('Image Build') {
// agent { label 'buildah' }
// when {
// // fake condition for now
// branch 'master'
// }
// steps {
// echo 'Building Image from Jar File'
// }
// }
// stage('Push Docker Image') {
// when {
// branch 'master'
// }
// steps {
// script {
// }
// }
// }
// stage('Update GitOps Repo') {
// when {
// branch 'master'
// }
// steps {
// }
// }
// stage ('Verify Deployment to Dev') {
// steps {
// script {
// openshift.withCluster() {
// def dcObj = openshift.selector('dc', env.APP_NAME).object()
// def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
// podSelector.untilEach {
// echo "pod: ${it.name()}"
// return it.object().status.containerStatuses[0].ready
// }
// }
// }
// }
// }
// stage('Promote to Stage') {
// steps {
// script {
// openshift.withCluster() {
// openshift.tag("${env.STAGE1}/${env.APP_NAME}:latest", "${env.STAGE2}/${env.APP_NAME}:latest")
// }
// }
// }
// }
// stage ('Verify Deployment to Stage') {
// steps {
// script {
// openshift.withCluster() {
// openshift.withProject("${STAGE2}") {
// def dcObj = openshift.selector('dc', env.APP_NAME).object()
// def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
// podSelector.untilEach {
// echo "pod: ${it.name()}"
// return it.object().status.containerStatuses[0].ready
// }
// }
// }
// }
// }
// }
// stage('Promote to Prod') {
// steps {
// withDockerRegistry([credentialsId: "${STAGE1}-nonprod-credentials", url: "${SRC_API_URL}"]) {
// withDockerRegistry([credentialsId: "${STAGE1}-prod-credentials", url: "${DEST_API_URL}"]) {
// sh """
// oc image mirror --insecure=true ${SRC_REGISTRY}/${STAGE2}/${APP_NAME}:latest ${DEST_REGISTRY}/${STAGE3}/${APP_NAME}:latest
// """
// }
// }
// }
// }
// stage ('Verify Deployment to Prod') {
// steps {
// script {
// openshift.withCluster() {
// def secretData = openshift.selector('secret/prod-cluster-credentials').object().data
// def encodedAPI = secretData.api
// def encodedToken = secretData.token
// env.API = sh(script:"set +x; echo ${encodedAPI} | base64 --decode", returnStdout: true).replaceAll(/https?/, 'insecure')
// env.TOKEN = sh(script:"set +x; echo ${encodedToken} | base64 --decode", returnStdout: true)
// }
// openshift.withCluster( env.API, env.TOKEN ) {
// openshift.withProject("${STAGE3}") {
// def dcObj = openshift.selector('dc', env.APP_NAME).object()
// def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"])
// podSelector.untilEach {
// echo "pod: ${it.name()}"
// return it.object().status.containerStatuses[0].ready
// }
// }
// }
// }
// }
// }
}
post {
// stage executed always, regardless of the completion status of the Pipeline’s or stage’s run
always {
node('master') {
// dir('widgets') {
// // publish screenshots of failed integration tests, if any
// publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'cypress/cypress/screenshots', reportFiles: '**', reportName: 'Cypress screenshots', reportTitles: ''])
// // publish videos of the tests, if any
// publishHTML([allowMissing: true, alwaysLinkToLastBuild: true, keepAll: true, reportDir: 'cypress/cypress/videos', reportFiles: '**', reportName: 'Cypress videos', reportTitles: ''])
// }
// send an email with the build result to the specified recipients
emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
to: "${EMAIL_RECIPIENT_LIST}",
subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
}
}
// stage executed after every other post condition has been evaluated, regardless of the Pipeline or stage’s status.
cleanup {
node('master') {
// clean up the pipeline workspace
cleanWs()
}
}
}
}