-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile-services.groovy
174 lines (152 loc) · 8.18 KB
/
Jenkinsfile-services.groovy
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
170
171
172
173
174
node('zOS') {
stage('Checkout Git Code to Jenkins on zOS') {
git credentialsId: 'git', url: 'https://github.com/Jack-Billings-IBM/catalog.git'
env.JAVA_HOME = "/usr/lpp/java/J8.0_64"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
}
stage('Update Copybooks on zOS') {
sh '/usr/lpp/IBM/dbb/bin/groovyz dbb/copyToPDS.groovy'
}
stage('Rebuild Catalog COBOL Program') {
sh '/usr/lpp/IBM/dbb/bin/groovyz dbb/build.groovy --workspace /usr/lpp/ported/jenkins/workspace/catalog/dbb --application catalog --outDir /usr/lpp/ported/jenkins/workspace/catalog/dbb --hlq IBMUSER.DBB /usr/lpp/ported/jenkins/workspace/catalog/dbb/catalog/cobol/dfh0xcmn.cbl'
}
}
node('master') {
jdk = tool name: 'JDK8'
env.JAVA_HOME = "${jdk}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
stage('Checkout Git Code to Jenkins on OpenShift') { // for display purposes
// Get some code from a GitHub repository
println "project name is catalogTest"
git credentialsId: 'git', url: 'https://github.com/Jack-Billings-IBM/catalogZDT.git'
}
stage('Rebuild zOS Connect Services') {
println "Calling zconbt"
def output = sh (returnStdout: true, script: 'pwd')
println output
sh "${WORKSPACE}/zconbt/bin/zconbt --properties=${WORKSPACE}/properties/inquireCatalog.properties --file=${WORKSPACE}/archives/inquireCatalog.sar "
println "Called zconbt for inquireCatalog"
sh "${WORKSPACE}/zconbt/bin/zconbt --properties=${WORKSPACE}/properties/inquireSingle.properties --file=${WORKSPACE}/archives/inquireSingle.sar "
println "Called zconbt for inquireSingle"
println "Exiting Stage 2, entering Stage 3!"
}
stage('Check for and Handle Existing Services') {
println "Going to stop and remove existing service from zOS Connect Server if required"
def resp = stopAndDeleteRunningService("inquireSingle")
def resp2 = stopAndDeleteRunningService("inquireCatalog")
println "Cleared the field for service deploy: "+resp
println "Cleared the field for service deploy: "+resp2
}
stage('Deploy to z/OS Connect Server'){
//call code to deploy the service. passing the name of the service as a param
def sarFileName ="inquireSingle.sar"
installSar(sarFileName)
def sarFileName2 ="inquireCatalog.sar"
installSar(sarFileName2)
}
stage('Test Services') {
def serviceName = "inquireCatalog"
testServices(serviceName)
def serviceName2 = "inquireSingle"
testServices(serviceName2)
}
stage("Push to GitHub") {
sh "rm response.json"
sh "rm responseDel.json"
sh "rm responseStop.json"
sh "git config --global user.email '[email protected]'"
sh "git config --global user.name 'Jack-Billings-IBM'"
sh "pwd"
sh "ls"
sh "git add -A"
sh "git commit -m 'new sar file'"
//need to add git credentials to jenkins
withCredentials([usernamePassword(credentialsId: 'git', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]){
sh('''
git config --local credential.helper "!f() { echo username=\\$GIT_USERNAME; echo password=\\$GIT_PASSWORD; }; f"
git push origin HEAD:master
''')
}
}
}
//Will stop a running service if required and delete it
def stopAndDeleteRunningService(service_name){
println("Checking existence/status of Service name: "+service_name)
//will be building curl commands, so saving the tail end for appending
def urlval = "10.1.1.2:9080/zosConnect/services/"+service_name
def stopurlval = "10.1.1.2:9080/zosConnect/services/"+service_name+"?status=stopped"
//complete curl command will be saved in these values
def command_val = ""
def stop_command_val = ""
def del_command_val = ""
//call utility to get saved credentials and build curl command with it. Commands were built to check, stop and delete service
//curl command spits out response code into stdout. that's then held in response field to evaluate
command_val = "curl -o response.json -w %{response_code} --header 'Content-Type:application/json' --insecure "+urlval
stop_command_val = "curl -X PUT -o responseStop.json --header \'Accept: application/json\' --header 'Content-Type:application/json' --insecure "+stopurlval
del_command_val = "curl -X DELETE -o responseDel.json --header 'Content-Type:application/json' --insecure "+urlval
// this checks the initial status of the service. If it exists, HTTP Response Code will be 200
def response = sh (script: command_val, returnStdout: true)
println ""
println "Response code is: "+response
if(response != "200"){
println "This Service does not exist on the server. Deploying for first Time"
return true
}
else{
println "Service already exists, stopping and deleting it now"
//reading status of existing service from response file. file was created during curl command.
def myObject = readJSON file: 'response.json'
def status = myObject.zosConnect.serviceStatus
println "Service status is "+status
if(status == "Started"){
//Stop API
def responseStop = sh (script: stop_command_val, returnStdout: true)
def myObjectStop = readJSON file: 'responseStop.json'
def statusStop = myObjectStop.zosConnect.serviceStatus
//ensure that status was actually stopped
println "New status of service : "+statusStop
//Delete API using curl command that was built
def responseDel = sh (script: del_command_val, returnStdout: true)
println "Service delete call complete"
return true
}
else{
println "Don't know why we hit this! Service is currently stopped......handle this if you like"
return false
}
return true
}
}
def installSar(sarFileName){
println "Starting sar deployment now"
def urlval = "10.1.1.2:9080/zosConnect/services/"
def respCode = ""
//call utility to get saved credentials and build curl command with it and sar file name and then execute command
//curl command spits out response code into stdout. that's then held in respCode field to evaluate
def command_val = "curl -X POST -o response.json -w %{response_code} --header 'Content-Type:application/zip' --data-binary @${WORKSPACE}/archives/"+sarFileName+" --insecure "+urlval
respCode = sh (script: command_val, returnStdout: true)
println "Service Installation Response code is: "+respCode
if(respCode == "201"){
println "Deployment completed successfully"
}else if(respCode == "409"){
error("Deployment failed due to it already existing")
}
}
def testServices(serviceName) {
println "Starting testing now"
def urlval = "10.1.1.2:9080/zosConnect/services/"+serviceName+"?action=invoke"
def respCode = ""
//def single = readJSON file: 'tests/inquireSingle_service_request.json'
if(serviceName == "inquireSingle") {
def single = '''{"DFH0XCMNOperation":{"ca_request_id":"01INQS","ca_inquire_single":{"ca_item_ref_req":40}}}'''
def command_val = "curl -g -X POST -o ${WORKSPACE}/tests/"+serviceName+"_service.json -w %{response_code} --header 'Content-Type: application/json' --data "+single+" --insecure "+urlval
respCode = sh (script: command_val, returnStdout: true)
println serviceName+" Service Test Response code is: "+respCode
}
else {
def catalog = '{"DFH0XCMNOperation":{"ca_request_id":"01INQC","ca_inquire_request":{"ca_list_start_ref":20}}}'
def command_val = "curl -g -X POST -o ${WORKSPACE}/tests/"+serviceName+"_service.json -w %{response_code} --header 'Content-Type: application/json' --header 'Content-Type: text/plain' --data "+catalog+" --insecure "+urlval
respCode = sh (script: command_val, returnStdout: true)
println serviceName+" Service Test Response code is: "+respCode
}
}