|
@@ -45,17 +45,29 @@ def process_folder(folder, import_type) {
|
45
|
45
|
|
46
|
46
|
sh "mkdir -p ${backup_folder}"
|
47
|
47
|
|
48
|
|
- files = findFiles(glob: "${folder}/*.xml")
|
|
48
|
+ // Use find command to get XML files and avoid error if none found
|
|
49
|
+ def fileList = sh(script: "find ${folder} -name '*.xml' || echo ''", returnStdout: true).trim().split('\n')
|
49
|
50
|
|
50
|
|
- for(file in files) {
|
51
|
|
- response = sh(script: """
|
52
|
|
- curl --location --request POST "${import_url}" \
|
53
|
|
- --header "Authorization: ${env.AUTH_TOKEN}" \
|
54
|
|
- --form "@${file}" \
|
55
|
|
- """, returnStdout: true).trim()
|
|
51
|
+ // Remove any empty strings from the list
|
|
52
|
+ fileList = fileList.findAll { it != '' }
|
|
53
|
+
|
|
54
|
+ // Check if we found any files
|
|
55
|
+ if (fileList.size() == 0) {
|
|
56
|
+ echo "No XML files found in ${folder}."
|
|
57
|
+ return
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ echo "Detected files: ${fileList.join(', ')}"
|
|
61
|
+
|
|
62
|
+ for(file in fileList) {
|
|
63
|
+ def response = sh(script: """
|
|
64
|
+ curl --location --request POST "${import_url}" \
|
|
65
|
+ --header 'Authorization: stat ${env.AUTH_TOKEN}' \
|
|
66
|
+ --form "=@${file}"
|
|
67
|
+ """, returnStdout: true).trim()
|
56
|
68
|
|
57
|
69
|
if(response != '') { // or other success condition
|
58
|
|
- sh "mv ${file} ${backup_folder}/"
|
|
70
|
+ sh "mv \"${file}\" \"${backup_folder}/\""
|
59
|
71
|
echo "API Response: ${response}"
|
60
|
72
|
} else {
|
61
|
73
|
echo "Error while uploading ${file} to ${import_url}"
|