diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..9b38f09 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,58 @@ +pipeline { + agent any + + // Assurez-vous d'avoir configuré l'outil "NodeJS 20" dans Jenkins (Global Tool Configuration) + tools { + nodejs 'NodeJS 20' + } + + environment { + // Variables pour éviter de répéter les chemins + FRONT_DEST = '/var/www/xeewy.be' + BACK_DEST = '/var/www/xeewy/backend' + SERVICE_NAME = 'xeewy-backend' + } + + stages { + stage('Build Frontend') { + steps { + echo '--- Building React Frontend ---' + dir('frontend') { + sh 'npm install' + sh 'npm run build' + } + } + } + + stage('Deploy Frontend') { + steps { + echo '--- Deploying Frontend to Apache folder ---' + // On vide le dossier cible (sauf s'il est vide) et on copie le build + // Note : Adaptez 'build' en 'dist' si vous utilisez ViteJS + sh "rm -rf ${FRONT_DEST}/*" + sh "cp -r frontend/build/* ${FRONT_DEST}/" + } + } + + stage('Deploy Backend') { + steps { + echo '--- Deploying Backend Code ---' + // On copie le code backend vers sa destination + // On exclut node_modules pour éviter de copier des milliers de fichiers inutilement + sh "rsync -av --exclude='node_modules' backend/ ${BACK_DEST}/" + + dir("${BACK_DEST}") { + sh 'npm install --production' + } + } + } + + stage('Restart Service') { + steps { + echo '--- Restarting Node.js Service ---' + // Nécessite la règle sudo NOPASSWD configurée précédemment + sh "sudo systemctl restart ${SERVICE_NAME}" + } + } + } +} \ No newline at end of file