Modified jenkinsfile

This commit is contained in:
Antoni Nuñez Romeu
2026-03-19 11:44:53 +01:00
parent 3ce8096d63
commit 71b2c5f2ed

31
Jenkinsfile vendored
View File

@@ -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
git pull
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
pm2 restart ${env.PM2_APP}
""".stripIndent()
// SSH options for non-interactive, secure connection