From 71b2c5f2ed59ca9d6f2e440e76b32065aa830cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoni=20Nu=C3=B1ez=20Romeu?= Date: Thu, 19 Mar 2026 11:44:53 +0100 Subject: [PATCH] Modified jenkinsfile --- Jenkinsfile | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8e4c628..fc77297 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,11 +6,10 @@ pipeline { REMOTE_DIR = '/home/zouklambadabcn.com/public_html' PM2_APP = 'ZLB' // Name of Jenkins Credentials (Username with private key) to SSH - SSH_CREDS = 'ssh-remote' // <-- configure this in Jenkins Credentials + SSH_CREDS = 'root_ssh' // <-- configure this in Jenkins Credentials } options { - ansiColor('xterm') timestamps() } @@ -22,32 +21,12 @@ pipeline { withCredentials([sshUserPrivateKey(credentialsId: env.SSH_CREDS, keyFileVariable: 'SSH_KEY', usernameVariable: 'SSH_USER')]) { // Build the remote command to run def remoteCmd = """ - set -euo pipefail + set -e cd "${env.REMOTE_DIR}" - echo "[$(date)] PWD=$(pwd) on ${HOSTNAME}" - - # Ensure repo is cleanly updated - git fetch --all --prune - git reset --hard HEAD - git pull --rebase --autostash || git pull - - # Use npm if available, fallback to npx if needed - if command -v npm >/dev/null 2>&1; then - npm ci || npm install - npm run build - else - npx --yes npm@latest ci || npx --yes npm@latest install - npx --yes npm@latest run build - fi - - # Restart pm2 app - if command -v pm2 >/dev/null 2>&1; then - pm2 restart "${PM2_APP}" || pm2 start npm --name "${PM2_APP}" -- run start - pm2 save || true - else - echo 'pm2 not found in PATH' >&2 - exit 1 - fi + git pull + npm install + npm run build + pm2 restart ${env.PM2_APP} """.stripIndent() // SSH options for non-interactive, secure connection