|
@@ -0,0 +1,64 @@
|
|
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
|
+ }
|
|
37
|
+ }
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+def process_folder(folder, import_type) {
|
|
43
|
+ import_url = "${env.BASE_URL}${import_type}"
|
|
44
|
+ backup_folder = "${env.BACKUP_DIR}/${import_type}"
|
|
45
|
+
|
|
46
|
+ sh "mkdir -p ${backup_folder}"
|
|
47
|
+
|
|
48
|
+ files = findFiles(glob: "${folder}/*.xml")
|
|
49
|
+
|
|
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()
|
|
56
|
+
|
|
57
|
+ if(response != '') { // or other success condition
|
|
58
|
+ sh "mv ${file} ${backup_folder}/"
|
|
59
|
+ echo "API Response: ${response}"
|
|
60
|
+ } else {
|
|
61
|
+ echo "Error while uploading ${file} to ${import_url}"
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+}
|