-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsFile
57 lines (46 loc) · 2.18 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
node('maven') {
// define commands
def ocCmd = "/usr/local/bin/oc --token=`cat /var/run/secrets/kubernetes.io/serviceaccount/token` --server=https://openshift.default.svc.cluster.local --certificate-authority=/run/secrets/kubernetes.io/serviceaccount/ca.crt"
def mvnCmd = "mvn -s configuration/cicd-settings.xml"
stage:'Prerequisities'
git url: 'http://gogs:3000/gogs/pipeline-playground.git'
def eapResource = readFile('eap.json')
echo eapResource
// remove already created resources
openshiftDeleteResourceByJsonYaml('json':eapResource,'namespace':'dev', 'verbose':'false')
openshiftCreateResource('json':eapResource,'namespace':'dev', 'verbose':'false')
stage 'Build'
git branch: 'eap-7', url: 'http://gogs:3000/gogs/openshift-tasks.git'
def v = version()
sh "${mvnCmd} clean install -DskipTests=true"
stage 'Test'
sh "${mvnCmd} test"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
stage 'Push to Nexus'
sh "${mvnCmd} deploy -DskipTests=true"
stage 'Deploy DEV'
sh "rm -rf oc-build && mkdir -p oc-build/deployments"
sh "cp target/openshift-tasks.war oc-build/deployments/ROOT.war"
// clean up. keep the image stream
openshiftDeleteResourceByLabels('types': 'bc,dc,svc,route',keys:'app','values':'tasks','namespace':'dev')
// create build. override the exit code since it complains about exising imagestream
sh "${ocCmd} new-build --name=tasks --image-stream=wildfly --binary=true --labels=app=tasks -n dev || true"
// build image
sh "${ocCmd} start-build tasks --from-dir=oc-build --wait=true -n dev"
// deploy image
sh "${ocCmd} new-app tasks:latest -n dev"
sh "${ocCmd} expose svc/tasks -n dev"
stage 'Deploy STAGE'
input message: "Promote to STAGE?", ok: "Promote"
// tag for stage
sh "${ocCmd} tag dev/tasks:latest stage/tasks:${v}"
// clean up. keep the imagestream
sh "${ocCmd} delete bc,dc,svc,route -l app=tasks -n stage"
// deploy stage image
sh "${ocCmd} new-app tasks:${v} -n stage"
sh "${ocCmd} expose svc/tasks -n stage"
}
def version() {
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
matcher ? matcher[0][1] : null
}