Browse Source

modified jenkins file

Avinash 1 year ago
parent
commit
a3fa085663
1 changed files with 20 additions and 8 deletions
  1. 20
    8
      Jenkinsfile

+ 20
- 8
Jenkinsfile View File

45
 
45
 
46
     sh "mkdir -p ${backup_folder}"
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
         if(response != '') { // or other success condition
69
         if(response != '') { // or other success condition
58
-            sh "mv ${file} ${backup_folder}/"
70
+            sh "mv \"${file}\" \"${backup_folder}/\""
59
             echo "API Response: ${response}"
71
             echo "API Response: ${response}"
60
         } else {
72
         } else {
61
             echo "Error while uploading ${file} to ${import_url}"
73
             echo "Error while uploading ${file} to ${import_url}"

Loading…
Cancel
Save