forked from redhat-cop/spring-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
99 lines (70 loc) · 3.07 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
#!/usr/bin/groovy
////
// This pipeline requires the following plugins:
// Kubernetes Plugin 0.10
////
String ocpApiServer = env.OCP_API_SERVER ? "${env.OCP_API_SERVER}" : "https://openshift.default.svc.cluster.local"
node('master') {
env.NAMESPACE = readFile('/var/run/secrets/kubernetes.io/serviceaccount/namespace').trim()
env.TOKEN = readFile('/var/run/secrets/kubernetes.io/serviceaccount/token').trim()
env.OC_CMD = "oc --token=${env.TOKEN} --server=${ocpApiServer} --certificate-authority=/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=${env.NAMESPACE}"
env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '')
def projectBase = "${env.NAMESPACE}".replaceAll(/-dev/, '')
env.STAGE1 = "${projectBase}-dev"
env.STAGE2 = "${projectBase}-stage"
env.STAGE3 = "${projectBase}-prod"
}
node('maven') {
// def mvnHome = "/usr/share/maven/"
// def mvnCmd = "${mvnHome}bin/mvn"
def mvnCmd = 'mvn'
String pomFileLocation = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
stage('SCM Checkout') {
checkout scm
}
stage('Build') {
sh "${mvnCmd} clean install -DskipTests=true -f ${pomFileLocation}"
}
stage('Unit Test') {
sh "${mvnCmd} test -f ${pomFileLocation}"
}
// The following variables need to be defined at the top level and not inside
// the scope of a stage - otherwise they would not be accessible from other stages.
// Extract version and other properties from the pom.xml
//def groupId = getGroupIdFromPom("./pom.xml")
//def artifactId = getArtifactIdFromPom("./pom.xml")
//def version = getVersionFromPom("./pom.xml")
//println("Artifact ID:" + artifactId + ", Group ID:" + groupId)
//println("New version tag:" + version)
stage('Build Image') {
sh """
rm -rf oc-build && mkdir -p oc-build/deployments
for t in \$(echo "jar;war;ear" | tr ";" "\\n"); do
cp -rfv ./target/*.\$t oc-build/deployments/ 2> /dev/null || echo "No \$t files"
done
${env.OC_CMD} start-build ${env.APP_NAME} --from-dir=oc-build --wait=true --follow=true || exit 1
"""
}
stage("Verify Deployment to ${env.STAGE1}") {
openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE1}", verifyReplicaCount: true)
input "Promote Application to Stage?"
}
stage("Promote To ${env.STAGE2}") {
sh """
${env.OC_CMD} tag ${env.STAGE1}/${env.APP_NAME}:latest ${env.STAGE2}/${env.APP_NAME}:latest
"""
}
stage("Verify Deployment to ${env.STAGE2}") {
openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE2}", verifyReplicaCount: true)
input "Promote Application to Prod?"
}
stage("Promote To ${env.STAGE3}") {
sh """
${env.OC_CMD} tag ${env.STAGE2}/${env.APP_NAME}:latest ${env.STAGE3}/${env.APP_NAME}:latest
"""
}
stage("Verify Deployment to ${env.STAGE3}") {
openshiftVerifyDeployment(deploymentConfig: "${env.APP_NAME}", namespace: "${STAGE3}", verifyReplicaCount: true)
}
}
println "Application ${env.APP_NAME} is now in Production!"