forked from redhat-cop/ninja-board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
77 lines (67 loc) · 1.9 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
@Library('cop-library') _
openshift.withCluster() {
env.localToken = readFile('/var/run/secrets/kubernetes.io/serviceaccount/token').trim()
env.NAMESPACE = openshift.project()
}
pipeline {
agent {
label 'maven'
}
stages {
stage ('Fetch Source Code') {
steps {
git url: "${SOURCE_REPOSITORY_URL}", branch: "${SOURCE_REPOSITORY_REF}"
}
}
stage('Build Application'){
steps {
sh "mvn clean install -DskipTests=true"
}
}
stage('Build Image'){
steps {
sh """
rm -rf oc-build && mkdir -p oc-build/deployments
cp -v target/*.war oc-build/deployments/
"""
script {
openshift.withCluster() {
openshift.withProject() {
openshift.selector("bc", "${APPLICATION_NAME}").startBuild("--from-dir=oc-build").logs("-f")
}
}
}
}
}
stage ('Verify Deployment to Dev') {
steps {
rollout([projectName: "${DEV_NAMESPACE}", resourceKindAndName: "dc/${APPLICATION_NAME}", latest: false])
}
}
stage ('Promote to Prod') {
agent none
steps {
script {
input message: "Promote Ninja Board to Prod?"
}
}
}
stage ('Tag Image to Prod'){
steps {
script {
openshift.withCluster() {
openshift.withProject() {
echo "Promoting via tag from ${DEV_NAMESPACE} to ${PROD_NAMESPACE}/${APPLICATION_NAME}"
tagImage(sourceImagePath: "${DEV_NAMESPACE}", sourceImageName: "${APPLICATION_NAME}", toImagePath: "${PROD_NAMESPACE}", toImageName: "${APPLICATION_NAME}", toImageTag: "latest")
}
}
}
}
}
stage ('Verify Deployment to Prod') {
steps {
rollout([projectName: "${PROD_NAMESPACE}", resourceKindAndName: "dc/${APPLICATION_NAME}", latest: false])
}
}
}
}