// Simple pipeline for deploying spring pipeline { agent any stages { stage('Stop previous deploy') { environment { PATH = "/var/lib/jenkins/.nvm/versions/node/v20.9.0/bin:${env.PATH}" } steps { sh "pm2 delete ${env.JOB_NAME} || true" } } stage('Build java') { steps { sh './mvnw clean package' } } stage('Build frontend') { environment { PATH = "/var/lib/jenkins/.nvm/versions/node/v20.9.0/bin:${env.WORKSPACE}/node_modules/.bin:${env.PATH}" } steps { sh 'cd frontend && npm install && npm run build' dir("src/main/resources/frontend") { sh 'pnpm i' sh 'pnpm build' } } } stage('Deploy') { environment { PATH = "/var/lib/jenkins/.nvm/versions/node/v20.9.0/bin:${env.PATH}" } steps { // Remove previous deploy sh 'rm /var/www/jerguero/* || true' // Copy new deploy sh 'cp /var/lib/jenkins/workspace/jerguero/target/jerguero-0.0.1.jar /var/www/jerguero' // Copy launch file sh 'cp run.sh /var/www/jerguero' // make launch file executable sh 'chmod +x /var/www/jerguero/run.sh' // run launch file with pm2 sh "pm2 start /var/www/jerguero/run.sh --name ${env.JOB_NAME}" // Save state sh 'pm2 save' } } } }