mirror of
https://github.com/Ichitux/lambada-fiesta-live.git
synced 2026-05-15 16:12:20 +02:00
Modified jenkinsfile
This commit is contained in:
33
Jenkinsfile
vendored
33
Jenkinsfile
vendored
@@ -6,11 +6,10 @@ pipeline {
|
|||||||
REMOTE_DIR = '/home/zouklambadabcn.com/public_html'
|
REMOTE_DIR = '/home/zouklambadabcn.com/public_html'
|
||||||
PM2_APP = 'ZLB'
|
PM2_APP = 'ZLB'
|
||||||
// Name of Jenkins Credentials (Username with private key) to SSH
|
// 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 {
|
options {
|
||||||
ansiColor('xterm')
|
|
||||||
timestamps()
|
timestamps()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,32 +21,12 @@ pipeline {
|
|||||||
withCredentials([sshUserPrivateKey(credentialsId: env.SSH_CREDS, keyFileVariable: 'SSH_KEY', usernameVariable: 'SSH_USER')]) {
|
withCredentials([sshUserPrivateKey(credentialsId: env.SSH_CREDS, keyFileVariable: 'SSH_KEY', usernameVariable: 'SSH_USER')]) {
|
||||||
// Build the remote command to run
|
// Build the remote command to run
|
||||||
def remoteCmd = """
|
def remoteCmd = """
|
||||||
set -euo pipefail
|
set -e
|
||||||
cd "${env.REMOTE_DIR}"
|
cd "${env.REMOTE_DIR}"
|
||||||
echo "[$(date)] PWD=$(pwd) on ${HOSTNAME}"
|
git pull
|
||||||
|
npm install
|
||||||
# Ensure repo is cleanly updated
|
npm run build
|
||||||
git fetch --all --prune
|
pm2 restart ${env.PM2_APP}
|
||||||
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
|
|
||||||
""".stripIndent()
|
""".stripIndent()
|
||||||
|
|
||||||
// SSH options for non-interactive, secure connection
|
// SSH options for non-interactive, secure connection
|
||||||
|
|||||||
Reference in New Issue
Block a user