commit | author | age
|
d26619
|
1 |
pipeline { |
SU |
2 |
environment { |
|
3 |
DOMAIN='apps.ocp4.example.com' |
|
4 |
PRJ="hello-${env.BRANCH_NAME}-${env.BUILD_NUMBER}" |
|
5 |
APP='nodeapp' |
|
6 |
} |
|
7 |
agent { |
|
8 |
node { |
|
9 |
label 'nodejs' |
|
10 |
} |
|
11 |
} |
|
12 |
stages { |
|
13 |
stage('create') { |
|
14 |
steps { |
|
15 |
script { |
|
16 |
// Uncomment to get lots of debugging output |
|
17 |
//openshift.logLevel(1) |
|
18 |
openshift.withCluster() { |
|
19 |
echo("Create project ${env.PRJ}") |
|
20 |
openshift.newProject("${env.PRJ}") |
|
21 |
openshift.withProject("${env.PRJ}") { |
|
22 |
echo('Grant to developer read access to the project') |
|
23 |
openshift.raw('policy', 'add-role-to-user', 'view', 'developer') |
|
24 |
echo("Create app ${env.APP}") |
|
25 |
openshift.newApp("${env.GIT_URL}#${env.BRANCH_NAME}", "--strategy source", "--name ${env.APP}") |
|
26 |
} |
|
27 |
} |
|
28 |
} |
|
29 |
} |
|
30 |
} |
|
31 |
stage('build') { |
|
32 |
steps { |
|
33 |
script { |
|
34 |
openshift.withCluster() { |
|
35 |
openshift.withProject("${env.PRJ}") { |
|
36 |
def bc = openshift.selector('bc', "${env.APP}") |
|
37 |
echo("Wait for build from bc ${env.APP} to finish") |
|
38 |
timeout(5) { |
|
39 |
def builds = bc.related('builds').untilEach(1) { |
|
40 |
def phase = it.object().status.phase |
|
41 |
if (phase == "Failed" || phase == "Error" || phase == "Cancelled") { |
|
42 |
error 'OpenShift build failed or was cancelled' |
|
43 |
} |
|
44 |
return (phase == "Complete") |
|
45 |
} |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
stage('deploy') { |
|
53 |
steps { |
|
54 |
script { |
|
55 |
openshift.withCluster() { |
|
56 |
openshift.withProject("${env.PRJ}") { |
|
57 |
echo("Expose route for service ${env.APP}") |
|
58 |
// Default Jenkins settings to not allow to query properties of an object |
|
59 |
// So we cannot query the widlcard domain of the ingress controller |
|
60 |
// Nor the auto genereted host of a route |
|
61 |
openshift.expose("svc/${env.APP}", "--hostname ${env.PRJ}.${env.DOMAIN}") |
|
62 |
echo("Wait for deployment from dc ${env.APP} to finish") |
|
63 |
timeout(5) { |
|
64 |
openshift.selector('dc', "${env.APP}").rollout().status() |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
stage('test') { |
|
72 |
input { |
|
73 |
message 'About to test the application' |
|
74 |
ok 'Ok' |
|
75 |
} |
|
76 |
steps { |
|
77 |
echo "Check that '${env.PRJ}.${env.DOMAIN}' returns HTTP 200" |
|
78 |
sh "curl -s --fail ${env.PRJ}.${env.DOMAIN}" |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
post { |
|
83 |
always { |
|
84 |
script { |
|
85 |
openshift.withCluster() { |
|
86 |
echo("Delete project ${env.PRJ}") |
|
87 |
openshift.delete("project/${env.PRJ}") |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
} |