forked from siamaksade/openshift-jenkins-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile2
169 lines (160 loc) · 5.64 KB
/
Jenkinsfile2
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def version, mvnCmd = "mvn -s configuration/cicd-settings-nexus3.xml"
pipeline {
agent {
node {
label 'maven'
} //node
} //agent
stages {
stage('Build App') {
steps {
git branch: 'eap-7', url: 'http://gogs:3000/gogs/openshift-tasks.git'
script {
def pom = readMavenPom file: 'pom.xml'
version = pom.version
} //script
sh "${mvnCmd} install -DskipTests=true"
} //steps
} //stage
stage('Test') {
steps {
sh "${mvnCmd} test"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
} //steps
} //stage
stage('Code Analysis') {
steps {
script {
if (env.WITH_SONAR.toBoolean()) {
sh "${mvnCmd} sonar:sonar -Dsonar.host.url=http://sonarqube:9000 -DskipTests=true"
} else {
sh "${mvnCmd} site -DskipTests=true"
step([$class: 'CheckStylePublisher', unstableTotalAll:'300'])
step([$class: 'PmdPublisher', unstableTotalAll:'20'])
step([$class: 'FindBugsPublisher', pattern: '**/findbugsXml.xml', unstableTotalAll:'20'])
step([$class: 'JacocoPublisher'])
publishHTML (target: [keepAll: true, reportDir: 'target/site', reportFiles: 'project-info.html', reportName: "Site Report"])
} //if
} //script
} //steps
} //stage
stage('Archive App') {
steps {
sh "${mvnCmd} deploy -DskipTests=true -P nexus3"
} //steps
} //stage
stage('Create Image Builder') {
when {
expression {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
return !openshift.selector("bc", "${env.APP_NAME}").exists();
} //openshift.withproject
} //openshift.withcluster
} //expression
} //when
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.newBuild("--name=${env.APP_NAME}", "--image-stream=jboss-eap70-openshift:1.5", "--binary=true")
} //openshift.withproject
} //openshift.withcluster
} //script
} //steps
} //stage
stage('Build Image') {
steps {
sh "rm -rf oc-build && mkdir -p oc-build/deployments"
sh "cp target/openshift-tasks.war oc-build/deployments/ROOT.war"
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.selector("bc", "${env.APP_NAME}").startBuild("--from-dir=oc-build", "--wait=true")
} //openshift.withproject
} //openshift.withcluster
} //script
} //steps
} //stage
stage('Create DEV') {
when {
expression {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
return !openshift.selector('dc', "${env.APP_NAME}").exists()
} //openshift.withproject
} //openshift.withcluster
} //expression
} //when
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
def app = openshift.newApp("${env.APP_NAME}:latest")
app.narrow("svc").expose();
def dc = openshift.selector("dc", "${env.APP_NAME}")
while (dc.object().spec.replicas != dc.object().status.availableReplicas) {
sleep 10
} //while
openshift.set("triggers", "dc/${env.APP_NAME}", "--remove-all")
} //openshift.withproject
} //openshift.withcluster
} //script
} //steps
} //stage
stage('Deploy DEV') {
steps {
script {
openshift.withCluster() {
openshift.withProject(env.DEV_PROJECT) {
openshift.selector("dc", "${env.APP_NAME}").rollout().latest();
} //openshift.withproject
} //openshift.withcluster
} //script
} //steps
} //stage
stage('Promote to Test?') {
steps {
timeout(time:7, unit:'DAYS') {
input message: "Promote to Test?", ok: "Promote"
} //timeout
} //steps
} //stage
// node {
// label 'jenkins-slave-image-mgmt'
// } //node
// stages {
stage ('tag and push') {
agent {
node {
label 'jenkins-slave-image-mgmt'
} //node
} //agent
steps {
script {
sh """
set +x
echo "Promoting ${env.DEV_PROJECT}/${env.APP_NAME} -> ${env.TEST_REGISTRY}/${env.TEST_PROJECT}/${env.APP_NAME}"
skopeo --tls-verify=false copy --remove-signatures --src-creds ${env.DEV_REGISTRY_USER}:${env.DEV_REGISTRY_TOKEN} --dest-creds ${env.TEST_REGISTRY_USER}:${env.TEST_REGISTRY_TOKEN} docker://${env.DEV_REGISTRY}/${env.DEV_PROJECT}/${env.APP_NAME} docker://${env.TEST_REGISTRY}/${env.STAGE_PROJECT}/${env.APP_NAME}
"""
} //script
} //steps
} //stage
stage('Deploy Test') {
steps {
script {
openshift.withCluster('test') {
openshift.withProject(env.STAGE_PROJECT) {
if (openshift.selector('dc', 'tasks').exists()) {
openshift.selector('dc', 'tasks').delete()
openshift.selector('svc', 'tasks').delete()
openshift.selector('route', 'tasks').delete()
} //if
openshift.newApp("tasks:${version}").narrow("svc").expose()
} //openshift.withProject
} // openshift.withCluster
} //script
} //steps
} //stage
} //stages
} //pipeline