fix jenkinsfile intern errors

This commit is contained in:
matt committed 2026-10-18 00:07:04 -07:00
1 parent 78bc4bce97
commit 5e660b04de
1 file changed
+38 -67
+38 -67
View File
@@ -2,7 +2,7 @@ pipeline {
agent any agent any
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Global environment variables – change as needed // Global environment variables - change as needed
// ------------------------------------------------------------------ // ------------------------------------------------------------------
environment { environment {
DEBIAN_IP = 'debian_machine_ip' DEBIAN_IP = 'debian_machine_ip'
@@ -19,14 +19,14 @@ pipeline {
string(name: 'BT_USB_ID', defaultValue: '0bda:c821', description: 'USB ID of the BLE dongle') string(name: 'BT_USB_ID', defaultValue: '0bda:c821', description: 'USB ID of the BLE dongle')
} }
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
// Stages // Stages
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
stages { stages {
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
// 1️⃣ Build a unique screen session name // 1. Build a unique screen session name
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
stage('Prepare Screen Name') { stage('Prepare Screen Name') {
steps { steps {
script { script {
@@ -36,98 +36,69 @@ pipeline {
// keep only the last 6 digits → guarantees uniqueness // keep only the last 6 digits → guarantees uniqueness
env.SCREEN_SESSION = env.SCREEN_SESSION =
"ble_test_${String.format('%06d', epochSec % 1_000_000)}" "ble_test_${String.format('%06d', epochSec % 1_000_000)}"
sh "echo Screen ID - ${env.SCREEN_SESSION}"
} }
} }
} }
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
// 2️⃣ Ensure screen is installed (runs only once) // 2. Ensure screen is installed (runs only once)
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
stage('Ensure screen is present') { stage('Ensure screen is present') {
steps { steps {
sshagent([env.SSH_CREDENTIALS_ID]) { sshagent([env.SSH_CREDENTIALS_ID]) {
sh """ sh """
ssh -o StrictHostKeyChecking=no \ ssh -o StrictHostKeyChecking=no root@${params.host_ip} -o ServerAliveInterval=60 -o ServerAliveCountMax=120 << EOF
-o ServerAliveInterval=60 \ if ! command -v screen > /dev/null; then
-o ServerAliveCountMax=120 \ echo "screen not found - installing"
root@${params.host_ip} <<'EOF' apt-get update && apt-get install -y screen
if ! command -v screen > /dev/null; then fi
echo "screen not found – installing"
apt-get update && apt-get install -y screen
fi
EOF
""" """
} }
} }
} }
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
// 3️⃣ Run the BLE test inside a detached screen session // 3. Run the BLE test inside a detached screen session
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
stage('Run BLE Test') { stage('Run BLE Test') {
steps { steps {
retry(3) { // 3× retry on transient SSH hiccups retry(3) { // 3× retry on transient SSH hiccups
timeout(time: 8, unit: 'HOURS') { // 8‑hour hard timeout timeout(time: 8, unit: 'HOURS') { // 8‑hour hard timeout
sshagent([env.SSH_CREDENTIALS_ID]) { sshagent([env.SSH_CREDENTIALS_ID]) {
sh """ sh """
ssh -o StrictHostKeyChecking=no \ ssh -o StrictHostKeyChecking=no root@${params.host_ip} -o ServerAliveInterval=60 -o ServerAliveCountMax=120 << EOF
-o ServerAliveInterval=60 \ # Start test in detached screen
-o ServerAliveCountMax=120 \ screen -dmS ${env.SCREEN_SESSION} bash -c '
root@${params.host_ip} <<'EOF' usbreset ${params.BT_USB_ID}
# Start test in detached screen sleep 5
screen -dmS ${env.SCREEN_SESSION} bash -c ' cd /opt/ble-test/ble_api
echo "===== BLE test starting: \$(date)" > /tmp/ble_test.log git pull
usbreset ${params.BT_USB_ID} cd /opt/ble-test/ble_api/api
sleep 5 python3 -u ${REMOTE_SCRIPT} ${params.test_count}
cd /opt/ble-test/ble_api '
git pull # Give screen a moment to spin up
cd /opt/ble-test/ble_api/api sleep 2
python3 -u ${REMOTE_SCRIPT} ${params.test_count} 2>&1 | tee -a /tmp/ble_test.log
echo "===== BLE test finished: \$(date)" >> /tmp/ble_test.log
'
# Give screen a moment to spin up
sleep 2
EOF
""" """
} }
// ------------------------------------------------------------------
// 3a. Verify that the test finished successfully
// ------------------------------------------------------------------
sh """
ssh -o StrictHostKeyChecking=no \
-o ServerAliveInterval=60 \
-o ServerAliveCountMax=120 \
root@${params.host_ip} <<'EOF'
if grep -q "BLE test finished" /tmp/ble_test.log; then
echo "Test completed successfully."
else
echo "Test did NOT finish – aborting build."
exit 1
fi
EOF
"""
} }
} }
} }
} }
} }
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
// Post‑build cleanup – kill the remote screen session // Post‑build cleanup - kill the remote screen session
// ───────────────────────────────────────────────────────────────────── // ---------------------------------------------------------------------
post { post {
always { always {
sshagent([env.SSH_CREDENTIALS_ID]) { sshagent([env.SSH_CREDENTIALS_ID]) {
sh """ sh """
ssh -o StrictHostKeyChecking=no \ ssh -o StrictHostKeyChecking=no root@${params.host_ip} -o ServerAliveInterval=60 -o ServerAliveCountMax=120 << EOF
-o ServerAliveInterval=60 \ if screen -list | grep -q ${env.SCREEN_SESSION}; then
-o ServerAliveCountMax=120 \ screen -S ${env.SCREEN_SESSION} -X quit
root@${params.host_ip} <<'EOF' fi
if screen -list | grep -q ${env.SCREEN_SESSION}; then
screen -S ${env.SCREEN_SESSION} -X quit
fi
EOF
""" """
} }
} }