From f40bba753e570fd35ed73ef09062ccb8c6829287 Mon Sep 17 00:00:00 2001 From: matt Date: Sat, 17 Oct 2026 23:57:51 -0700 Subject: [PATCH] fix jenkinsfile num error --- api/Jenkinsfile.ble_test | 129 ++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/api/Jenkinsfile.ble_test b/api/Jenkinsfile.ble_test index 426221a..02f09a6 100644 --- a/api/Jenkinsfile.ble_test +++ b/api/Jenkinsfile.ble_test @@ -25,84 +25,87 @@ pipeline { stages { // --------------------------------------------------------------- - // 1️⃣ Prepare a unique screen session name + // 1️⃣ Generate a unique screen session name // --------------------------------------------------------------- stage('Prepare Screen Name') { steps { script { - // epoch seconds truncated to the last 6 digits - def epochSec = System.currentTimeMillis() / 1000 + // 1) Get epoch seconds (long) + long epochSec = (System.currentTimeMillis() / 1000L) as long + + // 2) Keep only the last 6 digits to avoid collisions env.SCREEN_SESSION = "ble_test_${String.format('%06d', epochSec % 1_000_000)}" } } } // --------------------------------------------------------------- - // 2️⃣ Verify / install screen (runs only once) + // 2️⃣ Ensure screen is installed (runs only once) // --------------------------------------------------------------- stage('Ensure screen is present') { steps { sshagent([env.SSH_CREDENTIALS_ID]) { - sh """ - ssh -o StrictHostKeyChecking=no \\ - -o ServerAliveInterval=60 \\ - -o ServerAliveCountMax=120 \\ - root@${params.host_ip} <<'EOF' - # If screen is missing, install it - if ! command -v screen > /dev/null; then - echo "screen not found – installing" - apt-get update && apt-get install -y screen - fi - EOF - """ + sh '''\ +ssh -o StrictHostKeyChecking=no \ + -o ServerAliveInterval=60 \ + -o ServerAliveCountMax=120 \ + root@${params.host_ip} <<'EOF' +if ! command -v screen > /dev/null; then + echo "screen not found – installing" + apt-get update && apt-get install -y screen +fi +EOF +''' } } } // --------------------------------------------------------------- - // 3️⃣ Run the BLE test in a detached screen session + // 3️⃣ Run the BLE test inside a detached screen session // --------------------------------------------------------------- stage('Run BLE Test') { steps { - retry(3) { - timeout(time: 8, unit: 'HOURS') { + retry(3) { // 3× retry on transient SSH hiccups + timeout(time: 8, unit: 'HOURS') { // 8‑hour hard timeout sshagent([env.SSH_CREDENTIALS_ID]) { - sh """ - ssh -o StrictHostKeyChecking=no \\ - -o ServerAliveInterval=60 \\ - -o ServerAliveCountMax=120 \\ - root@${params.host_ip} <<'EOF' - # Start the test in a detached screen session - screen -dmS ${env.SCREEN_SESSION} bash -c ' - echo "===== BLE test starting: \$(date)" > /tmp/ble_test.log - usbreset ${params.BT_USB_ID} - sleep 5 - cd /opt/ble-test/ble_api - git pull - cd /opt/ble-test/ble_api/api - 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 - """ + sh '''\ +ssh -o StrictHostKeyChecking=no \ + -o ServerAliveInterval=60 \ + -o ServerAliveCountMax=120 \ + root@${params.host_ip} <<'EOF' +# Start test in detached screen +screen -dmS ${env.SCREEN_SESSION} bash -c ' + echo "===== BLE test starting: $(date)" > /tmp/ble_test.log + usbreset ${params.BT_USB_ID} + sleep 5 + cd /opt/ble-test/ble_api + git pull + cd /opt/ble-test/ble_api/api + 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 +''' } - // Verify that the test finished - 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 - """ + // ------------------------------------------------------------------ + // 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 +''' } } } @@ -115,16 +118,16 @@ pipeline { post { always { sshagent([env.SSH_CREDENTIALS_ID]) { - sh """ - ssh -o StrictHostKeyChecking=no \\ - -o ServerAliveInterval=60 \\ - -o ServerAliveCountMax=120 \\ - root@${params.host_ip} <<'EOF' - if screen -list | grep -q ${env.SCREEN_SESSION}; then - screen -S ${env.SCREEN_SESSION} -X quit - fi - EOF - """ + sh '''\ +ssh -o StrictHostKeyChecking=no \ + -o ServerAliveInterval=60 \ + -o ServerAliveCountMax=120 \ + root@${params.host_ip} <<'EOF' +if screen -list | grep -q ${env.SCREEN_SESSION}; then + screen -S ${env.SCREEN_SESSION} -X quit +fi +EOF +''' } } }