-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpboiler
47 lines (43 loc) · 1.94 KB
/
httpboiler
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
pipeline {
agent any
stages {
stage('Check and Delete') {
steps {
script {
// Set the URL of the remote API and the item ID you want to check/delete
def apiUrl = 'https://example.com/api/items'
def itemId = '123'
// Perform a GET request to check if the item exists
def response = httpRequest(
acceptType: 'APPLICATION_JSON',
httpMode: 'GET',
responseHandle: 'NONE',
url: "${apiUrl}/${itemId}"
)
// Check the HTTP status code
if (response.getResponseCode() == 200) {
// Item exists, perform a DELETE request
def deleteResponse = httpRequest(
acceptType: 'APPLICATION_JSON',
contentType: 'APPLICATION_JSON',
httpMode: 'DELETE',
responseHandle: 'NONE',
url: "${apiUrl}/${itemId}"
)
// Check the HTTP status code for the DELETE request
if (deleteResponse.getResponseCode() == 204) {
echo "Item deleted successfully."
} else {
error "Failed to delete item. Status code: ${deleteResponse.getResponseCode()}"
}
} else if (response.getResponseCode() == 404) {
// Item does not exist, continue with the pipeline
echo "Item not found. Continuing..."
} else {
error "Failed to check item existence. Status code: ${response.getResponseCode()}"
}
}
}
}
}
}