|
@@ -0,0 +1,94 @@
|
|
1
|
+pipeline {
|
|
2
|
+ agent any
|
|
3
|
+
|
|
4
|
+ environment {
|
|
5
|
+ BACKUP_DIR = './backup'
|
|
6
|
+ }
|
|
7
|
+
|
|
8
|
+ stages {
|
|
9
|
+ stage('Setup') {
|
|
10
|
+ steps {
|
|
11
|
+ script {
|
|
12
|
+ BRANCH_NAME = env.BRANCH_NAME.split('/')[-1] // Extract branch name
|
|
13
|
+
|
|
14
|
+ switch(BRANCH_NAME) {
|
|
15
|
+ case "test1":
|
|
16
|
+ env.BASE_URL = "https://test08.bizgaze.com/Account/Import/"
|
|
17
|
+ env.AUTH_TOKEN = "6884972896664f4582e08f7f93da953d"
|
|
18
|
+ break
|
|
19
|
+ case "anwiqa":
|
|
20
|
+ env.BASE_URL = "https://qa.anwisystems.com/Account/Import/"
|
|
21
|
+ env.AUTH_TOKEN = "541c35d52a7b449f956175992619ed3a"
|
|
22
|
+ break
|
|
23
|
+ default:
|
|
24
|
+ error "Unknown branch: ${BRANCH_NAME}. Exiting."
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+ }
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ stage('Process XML files') {
|
|
31
|
+ steps {
|
|
32
|
+ script {
|
|
33
|
+ process_folder('./app', 'app')
|
|
34
|
+ process_folder('./report', 'report')
|
|
35
|
+ process_folder('./form', 'form')
|
|
36
|
+ commitChanges()
|
|
37
|
+ }
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+}
|
|
42
|
+
|
|
43
|
+def process_folder(folder, import_type) {
|
|
44
|
+ import_url = "${env.BASE_URL}${import_type}"
|
|
45
|
+ backup_folder = "${env.BACKUP_DIR}/${import_type}"
|
|
46
|
+
|
|
47
|
+ sh "mkdir -p ${backup_folder}"
|
|
48
|
+
|
|
49
|
+ // Use find command to get XML files and avoid error if none found
|
|
50
|
+ def fileList = sh(script: "find ${folder} -name '*.xml' || echo ''", returnStdout: true).trim().split('\n')
|
|
51
|
+
|
|
52
|
+ // Remove any empty strings from the list
|
|
53
|
+ fileList = fileList.findAll { it != '' }
|
|
54
|
+
|
|
55
|
+ // Check if we found any files
|
|
56
|
+ if (fileList.size() == 0) {
|
|
57
|
+ echo "No XML files found in ${folder}."
|
|
58
|
+ return
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ echo "Detected files: ${fileList.join(', ')}"
|
|
62
|
+
|
|
63
|
+ for(file in fileList) {
|
|
64
|
+ def response = sh(script: """
|
|
65
|
+ curl --location --request POST "${import_url}" \
|
|
66
|
+ --header 'Authorization: stat ${env.AUTH_TOKEN}' \
|
|
67
|
+ --form "=@${file}"
|
|
68
|
+ """, returnStdout: true).trim()
|
|
69
|
+
|
|
70
|
+ if(response != '') { // or other success condition
|
|
71
|
+ sh "mv \"${file}\" \"${backup_folder}/\""
|
|
72
|
+ echo "API Response: ${response}"
|
|
73
|
+ } else {
|
|
74
|
+ echo "Error while uploading ${file} to ${import_url}"
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+}
|
|
78
|
+
|
|
79
|
+def commitChanges() {
|
|
80
|
+ // Configure Git
|
|
81
|
+ sh """
|
|
82
|
+ git config user.email "jenkins@bizgaze.in"
|
|
83
|
+ git config user.name "jenkinstest"
|
|
84
|
+ """
|
|
85
|
+
|
|
86
|
+ // Check for changes
|
|
87
|
+ sh """
|
|
88
|
+ git checkout ${env.BRANCH_NAME}
|
|
89
|
+ git add .
|
|
90
|
+ git commit -m "Moved processed XML files to backup"
|
|
91
|
+ git push https://jenkinstest:Bizgaze123@code.bizgaze.com/devops.bizgaze/imports.git ${env.BRANCH_NAME}
|
|
92
|
+ """
|
|
93
|
+}
|
|
94
|
+
|