forked from OpenShiftDemos/openshift-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
111 lines (86 loc) · 3.55 KB
/
Jenkinsfile
File metadata and controls
111 lines (86 loc) · 3.55 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
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
node('maven') {
// define project name
def projectName = "openshift-tasks"
// define targets
def osDevTarget = "dev"
def osStageTarget = "stage"
stage ('Build') {
// git branch: 'master', url: 'http://gogs:3000/developer/openshift-tasks.git'
checkout scm
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS install -DskipTests=true"
}
}
stage ('Deploy DEV') {
// clean old build OpenShift
sh "rm -rf oc-build && mkdir -p oc-build/deployments"
// copy ressources
sh "cp target/openshift-tasks.war oc-build/deployments/ROOT.war"
sh "cp -r ./configuration oc-build/"
// change project to DEV
sh "oc project ${osDevTarget}"
// clean up. keep the image stream
sh "oc delete bc,dc,svc,route -l app=${projectName} -n ${osDevTarget}"
// create build. override the exit code since it complains about exising imagestream
sh "oc new-build --name=${projectName} --image-stream=jboss-eap70-openshift --allow-missing-imagestream-tags --binary=true --labels=app=${projectName} -n ${osDevTarget} || true"
// build image
sh "oc start-build ${projectName} --from-dir=oc-build --wait=true -n ${osDevTarget}"
// deploy image
sh "oc new-app ${projectName}:latest -n ${osDevTarget}"
sh "oc expose svc/${projectName} -n ${osDevTarget}"
}
stage ('Unit Tests') {
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS test -Dmaven.test.failure.ignore=true"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS sonar:sonar -Dsonar.host.url=http://sonarqube:9000 -Dmaven.test.failure.ignore=true"
}
}
stage ('Push to Nexus') {
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS deploy -DskipTests=true"
}
}
stage ('Deploy STAGE') {
timeout(time:5, unit:'MINUTES') {
input message: "Promote to STAGE?", ok: "Promote"
}
def v = version()
// tag for stage
sh "oc tag ${osDevTarget}/${projectName}:latest ${osStageTarget}/${projectName}:${v}"
// change project
sh "oc project ${osStageTarget}"
// clean up. keep the imagestream
sh "oc delete bc,dc,svc,route -l app=${projectName} -n ${osStageTarget}"
// deploy stage image
sh "oc new-app ${projectName}:${v} -n ${osStageTarget}"
sh "oc expose svc/${projectName} -n ${osStageTarget}"
}
stage ('Integration Tests') {
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS verify -Dmaven.test.failure.ignore=true"
}
step([$class: 'JUnitResultArchiver', testResults: '**/target/failsafe-reports/TEST-*.xml'])
// use a global settings file
configFileProvider(
[configFile(fileId: 'settings-global', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -s $MAVEN_SETTINGS sonar:sonar -Dsonar.host.url=http://sonarqube:9000 -Dmaven.test.failure.ignore=true"
}
}
}
def version() {
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
matcher ? matcher[0][1] : null
}