-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipelineUtils.groovy
30 lines (27 loc) · 975 Bytes
/
pipelineUtils.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
def withRetry(iterations, sleepTime, Closure closure) {
for (i = 0; true; i++) {
try {
println "Try number ${i}"
closure()
break
} catch (Exception e) {
if (i < iterations) {
sleep sleepTime
println "Retrying..."
} else {
error("Exceeded number of retries. Exception was: ${e.message}")
}
}
}
}
def restGet(url, credentialId, contentType = 'APPLICATION_JSON') {
res = httpRequest url: url, contentType: contentType, authentication: credentialId, consoleLogResponseBody: true
println res.getStatus()
res.getContent()
}
def restPost(url, credentialId, body, contentType = 'APPLICATION_JSON') {
res = httpRequest url: url, contentType: contentType, authentication: credentialId, httpMode: 'POST', requestBody: body, consoleLogResponseBody: true
println res.getStatus()
res.getContent()
}
return this