-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
78 lines (69 loc) · 2.25 KB
/
Jenkinsfile
File metadata and controls
78 lines (69 loc) · 2.25 KB
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
library identifier: "pipeline-library@v1.5",
retriever: modernSCM(
[
$class: "GitSCMSource",
remote: "https://github.com/redhat-cop/pipeline-library.git"
]
)
openshift.withCluster() {
env.NAMESPACE = openshift.project()
env.APP_NAME = "survey-service"
echo "Starting Pipeline for ${APP_NAME}..."
env.DEV = env.NAMESPACE.replaceAll(/-ci-cd/, '-dev')
env.TEST = env.NAMESPACE.replaceAll(/-ci-cd/, '-test')
env.DEMO = env.NAMESPACE.replaceAll(/-ci-cd/, '-demo')
}
pipeline {
// Use Jenkins Maven slave
// Jenkins will dynamically provision this as OpenShift Pod
// All the TESTs and steps of this Pipeline will be executed on this Pod
// After Pipeline completes the Pod is killed so every run will have clean
// workspace
agent {
label 'jenkins-slave-mvn'
}
// Pipeline TESTs start here
// Requeres at least one TEST
stages {
// Run Maven build, skipping tests
stage('Build'){
steps {
sh "mvn -B clean install -DskipTests=true"
}
}
// Run Maven unit tests
stage('Unit Test'){
steps {
sh "mvn -B test"
}
}
// Build Container Image using the artifacts DEMOuced in previous TESTs
stage('Build Container Image'){
steps {
// Copy the resulting artifacts into common directory
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
"""
// Build container image using local Openshift cluster
// Giving all the artifacts to OpenShift Binary Build
// This places your artifacts into right location inside your S2I image
// if the S2I image supports it.
binaryBuild(projectName: env.NAMESPACE, buildConfigName: env.APP_NAME, buildFromPath: "oc-build")
}
}
stage('Promote from Build to Dev') {
steps {
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.NAMESPACE, toImagePath: env.DEV, toImageName: 'spring-service')
}
}
stage('Verify Deployment to Dev') {
steps {
verifyDeployment(projectName: env.DEV, targetApp: 'spring-service')
}
}
}
}