generated from ibm-cloud-architecture/appmod-liberty-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
117 lines (109 loc) · 2.85 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
// Jenkinsfile for Liberty App - CI/CD
def templateName = 'gse-liberty'
openshift.withCluster() {
env.NAMESPACE = openshift.project()
env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '')
echo "Starting Pipeline for ${APP_NAME}..."
env.BUILD = "${env.NAMESPACE}"
env.DEV = "${APP_NAME}-dev"
env.STAGE = "${APP_NAME}-stage"
env.PROD = "${APP_NAME}-prod"
}
pipeline {
agent {
label "maven"
}
stages {
stage('preamble') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
echo "Using project: ${openshift.project()}"
echo "APPLICATION_NAME: ${params.APPLICATION_NAME}"
}
}
}
}
}
// Build Application using Maven
stage('Maven build') {
steps {
sh """
env
mvn -v
cd CustomerOrderServicesProject
mvn clean package
"""
}
}
// Run Maven unit tests
stage('Unit Test'){
steps {
sh """
mvn -v
cd CustomerOrderServicesProject
mvn test
"""
}
}
// Build Container Image using the artifacts produced in previous stages
stage('Build Liberty App Image'){
steps {
script {
// Build container image using local Openshift cluster
openshift.withCluster() {
openshift.withProject() {
timeout (time: 10, unit: 'MINUTES') {
// run the build and wait for completion
def build = openshift.selector("bc", "${params.APPLICATION_NAME}").startBuild("--from-dir=.")
// print the build logs
build.logs('-f')
}
}
}
}
}
}
stage('Promote to Dev') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.tag("${env.BUILD}/${env.APP_NAME}:latest", "${env.DEV}/${env.APP_NAME}:latest")
}
}
}
}
}
stage('Promote to Stage') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.tag("${env.DEV}/${env.APP_NAME}:latest", "${env.STAGE}/${env.APP_NAME}:latest")
}
}
}
}
}
stage('Promotion gate') {
steps {
script {
input message: 'Promote application to Production?'
}
}
}
stage('Promote to Prod') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.tag("${env.STAGE}/${env.APP_NAME}:latest", "${env.PROD}/${env.APP_NAME}:latest")
}
}
}
}
}
}
}