暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jenkinsfile 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. pipeline {
  2. agent any
  3. environment {
  4. BACKUP_DIR = './backup'
  5. }
  6. stages {
  7. stage('Setup') {
  8. steps {
  9. script {
  10. BRANCH_NAME = env.BRANCH_NAME.split('/')[-1] // Extract branch name
  11. switch(BRANCH_NAME) {
  12. case "test1":
  13. env.BASE_URL = "https://test08.bizgaze.com/Account/Import/"
  14. env.AUTH_TOKEN = "6884972896664f4582e08f7f93da953d"
  15. break
  16. case "anwiqa":
  17. env.BASE_URL = "https://qa.anwisystems.com/Account/Import/"
  18. env.AUTH_TOKEN = "541c35d52a7b449f956175992619ed3a"
  19. break
  20. default:
  21. error "Unknown branch: ${BRANCH_NAME}. Exiting."
  22. }
  23. }
  24. }
  25. }
  26. stage('Process XML files') {
  27. steps {
  28. script {
  29. process_folder('./app', 'app')
  30. process_folder('./report', 'report')
  31. process_folder('./form', 'form')
  32. }
  33. }
  34. }
  35. }
  36. }
  37. def process_folder(folder, import_type) {
  38. import_url = "${env.BASE_URL}${import_type}"
  39. backup_folder = "${env.BACKUP_DIR}/${import_type}"
  40. sh "mkdir -p ${backup_folder}"
  41. // Use find command to get XML files and avoid error if none found
  42. def fileList = sh(script: "find ${folder} -name '*.xml' || echo ''", returnStdout: true).trim().split('\n')
  43. // Remove any empty strings from the list
  44. fileList = fileList.findAll { it != '' }
  45. // Check if we found any files
  46. if (fileList.size() == 0) {
  47. echo "No XML files found in ${folder}."
  48. return
  49. }
  50. echo "Detected files: ${fileList.join(', ')}"
  51. for(file in fileList) {
  52. def response = sh(script: """
  53. curl --location --request POST "${import_url}" \
  54. --header 'Authorization: stat ${env.AUTH_TOKEN}' \
  55. --form "=@${file}"
  56. """, returnStdout: true).trim()
  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. }