This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
139 lines (125 loc) · 5.55 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
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
pipeline {
agent none
options {
disableResume()
}
stages {
stage("Build") {
agent { label "build" }
steps {
echo "Aborting all running jobs ..."
script {
abortAllPreviousBuildInProgress(currentBuild)
FORK_URL=sh(returnStdout: true, script: "echo ${GIT_URL} | sed s/bcgov/${CHANGE_FORK}/").trim()
}
script {
//VERSION="1.2"
// Use Pipeline-cli node project to build the open shift images, wiof-app-build ( open jdk image to build code with maven ) and wiof-build ( jboss web server image to host the web application )
echo "Building Openshift Images..."
sh "cd .openshiftio/.pipeline && ././npmw ci && DEBUG=* ././npmw run build -- --pr=${CHANGE_ID} --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
}
}
}
stage("Deploy App Changes to DEV") {
agent { label "build" } // Run on jenkins slave "build"
steps {
script {
// Use Pipeline-cli node project to deploy the wiof-build image to Dev Stage
echo "Deploying to DEV ..."
sh "cd .openshiftio/.pipeline && ./npmw ci && DEBUG=* ./npmw run deploy -- --pr=${CHANGE_ID} --env=dev --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
}
}
}
stage('Test API') {
agent { label "build" } // Run on jenkins slave "build"
steps{
script{
int response=sh(returnStdout: true, script: 'curl -o -i -L -s -w "%{http_code}" https://news.api.gov.bc.ca/api/Posts/Latest/home/default%20?api-version=1.0').trim()
//echo response
if ( response != 200 ){
echo "API not found"
exit 1
}else{
echo "API is valid"
}
}
}
}
stage("Approval For Test") {
agent { label "deploy" }
when {
expression { return env.CHANGE_TARGET == "master";}
beforeInput true;
}
input {
message "Is the Test complete on dev?"
parameters { }
submitter "SYSTEM"
}
steps {
script {
echo "Approved"
}
}
}
stage("Deploy App Changes to TEST") {
agent { label "deploy" }
when {
// Run Stage only if Pull Request is to master branch
expression { return env.CHANGE_TARGET == "master";}
beforeInput true;
}
steps {
script {
// Use Pipeline-cli node project to deploy the wiof-build image to Test Stage
echo "Deploying to Test ..."
sh "cd .openshiftio/.pipeline && ./npmw ci && DEBUG=* ./npmw run deploy -- --pr=${CHANGE_ID} --env=test --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
}
}
}
stage("Approval For PROD") {
agent { label "deploy" }
when {
expression { return env.CHANGE_TARGET == "master";}
beforeInput true;
}
input {
message "Is the test completed in Test Env?"
parameters { }
submitter "SYSTEM"
}
steps {
script {
echo "Approved"
}
}
}
stage("Deploy App Changes to PROD") {
agent { label "deploy" }
when {
// Run Stage only if Pull Request is to master branch
expression { return env.CHANGE_TARGET == "master";}
beforeInput true;
}
steps {
script {
// Use Pipeline-cli node project to deploy the wiof-build image to Prod Stage
echo "Deploying to Prod ..."
sh "cd .openshiftio/.pipeline && ./npmw ci && DEBUG=* ./npmw run deploy -- --pr=${CHANGE_ID} --env=prod --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
}
}
}
stage("Clean Out") {
agent { label "deploy" }
steps {
// Use Pipeline-cli node project to clean openshift objects
script {
// Fetch all builds for the Pull request from JIRA and mark them succesful (possibility of multiple builds since passing Build keys through jenkins adds an unsucessful build as a Bug)
echo "Clean out"
sh "cd .openshiftio/.pipeline && ./npmw ci && DEBUG=* ./npmw run clean -- --pr=${CHANGE_ID} --env=dev --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
sh "cd .openshiftio/.pipeline && ./npmw ci && DEBUG=* ./npmw run clean -- --pr=${CHANGE_ID} --env=build --git.branch.name=${CHANGE_BRANCH} --git.branch.merge=${CHANGE_BRANCH} --git.branch.remote=${CHANGE_BRANCH} --git.url=${FORK_URL}"
}
}
}
}
}