forked from redhat-cop/container-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
111 lines (96 loc) · 2.7 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
library identifier: "[email protected]",
retriever: modernSCM(
[
$class: "GitSCMSource",
remote: "https://github.com/redhat-cop/pipeline-library.git"
]
)
openshift.withCluster() {
env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml"
env.TARGET = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/target" : "target"
env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '')
env.BUILD = openshift.project()
env.DEV = "${APP_NAME}-dev"
env.STAGE = "${APP_NAME}-stage"
env.PROD = "${APP_NAME}-prod"
echo "Starting Pipeline for ${APP_NAME}..."
}
pipeline {
agent {
label 'maven'
}
stages {
stage('Git Checkout') {
steps {
git url: "${APPLICATION_SOURCE_REPO}", branch: "${APPLICATION_SOURCE_REF}"
}
}
stage('Build') {
steps {
sh "mvn -B clean install -DskipTests=true -f ${POM_FILE}"
}
}
stage('Unit Test') {
steps {
sh "mvn -B test -f ${POM_FILE}"
}
}
stage('Build Container Image') {
steps {
sh """
ls ${TARGET}/*
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
"""
binaryBuild(projectName: env.BUILD, buildConfigName: env.APP_NAME, buildFromPath: "oc-build")
}
}
stage('Promote from Build to Dev') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.BUILD, toImagePath: env.DEV)
}
}
stage('Verify Deployment to Dev') {
steps {
verifyDeployment(projectName: env.DEV, targetApp: env.APP_NAME)
}
}
stage('Promotion gate (Stage)') {
steps {
script {
input message: 'Promote Application to Stage?'
}
}
}
stage('Promote from Dev to Stage') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.DEV, toImagePath: env.STAGE)
}
}
stage('Verify Deployment to Stage') {
steps {
verifyDeployment(projectName: env.STAGE, targetApp: env.APP_NAME)
}
}
stage('Promotion gate (Prod)') {
steps {
script {
input message: 'Promote Application to Prod?'
}
}
}
stage('Promote from Stage to Prod') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.STAGE, toImagePath: env.PROD)
}
}
stage('Verify Deployment to Prod') {
steps {
verifyDeployment(projectName: env.PROD, targetApp: env.APP_NAME)
}
}
}
}
println "Application ${env.APP_NAME} is now in Production!"