설명 없음
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 3.4KB

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