Jenkinsfile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. pipeline {
  2. agent { label 'built-in' }
  3. environment {
  4. DEPLOY_FRONTEND = '/mnt/h/bitforum/sources'
  5. }
  6. stages {
  7. stage('Install') {
  8. steps {
  9. script {
  10. // package-lock.json 해시 비교해서 변경됐을 때만 재설치
  11. def lockHash = sh(
  12. script: 'sha256sum package-lock.json | cut -d" " -f1',
  13. returnStdout: true
  14. ).trim()
  15. def cacheFile = '.npm-lock-hash'
  16. def prevHash = fileExists(cacheFile)
  17. ? readFile(cacheFile).trim()
  18. : ''
  19. if (lockHash != prevHash) {
  20. echo "package-lock.json 변경 감지 → npm ci 실행"
  21. sh 'npm ci'
  22. writeFile file: cacheFile, text: lockHash
  23. } else {
  24. echo "package-lock.json 변경 없음 → 설치 스킵"
  25. }
  26. }
  27. }
  28. }
  29. stage('Build') {
  30. steps {
  31. sh 'npm run build'
  32. }
  33. }
  34. stage('Deploy') {
  35. steps {
  36. sh '''
  37. rsync -a --stats --delete \
  38. --exclude="web.config" \
  39. --exclude="ecosystem.config.js" \
  40. --exclude="restart.ps1" \
  41. --exclude=".env*" \
  42. .next/standalone/ ${DEPLOY_FRONTEND}/
  43. '''
  44. sh 'rsync -a --stats --delete .next/static/ ${DEPLOY_FRONTEND}/.next/static/'
  45. sh 'rsync -a --stats --delete public/ ${DEPLOY_FRONTEND}/public/'
  46. }
  47. }
  48. stage('Restart Frontend') {
  49. agent { label 'windows-host' }
  50. steps {
  51. bat 'chcp 65001 && powershell.exe -ExecutionPolicy Bypass -File H:\\IIS\\bitforum\\restart.ps1'
  52. }
  53. }
  54. }
  55. post {
  56. success { echo 'Frontend deploy success!' }
  57. failure { echo 'Frontend deploy failed!' }
  58. }
  59. }