fix jenkinsfile num error 2
This commit is contained in:
1 parent
f40bba753e
commit
78bc4bce97
1 file changed
+72
-71
+72
-71
@@ -19,115 +19,116 @@ 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️⃣ Generate a unique screen session name
|
// 1️⃣ Build a unique screen session name
|
||||||
// ---------------------------------------------------------------
|
// ─────────────────────────────────────────────────────────────────────
|
||||||
stage('Prepare Screen Name') {
|
stage('Prepare Screen Name') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// 1) Get epoch seconds (long)
|
// epoch seconds as a plain long
|
||||||
long epochSec = (System.currentTimeMillis() / 1000L) as long
|
long epochSec = System.currentTimeMillis() / 1000L
|
||||||
|
|
||||||
// 2) Keep only the last 6 digits to avoid collisions
|
// keep only the last 6 digits → guarantees uniqueness
|
||||||
env.SCREEN_SESSION = "ble_test_${String.format('%06d', epochSec % 1_000_000)}"
|
env.SCREEN_SESSION =
|
||||||
|
"ble_test_${String.format('%06d', epochSec % 1_000_000)}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ─────────────────────────────────────────────────────────────────────
|
||||||
// 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 \
|
||||||
-o ServerAliveInterval=60 \
|
-o ServerAliveInterval=60 \
|
||||||
-o ServerAliveCountMax=120 \
|
-o ServerAliveCountMax=120 \
|
||||||
root@${params.host_ip} <<'EOF'
|
root@${params.host_ip} <<'EOF'
|
||||||
if ! command -v screen > /dev/null; then
|
if ! command -v screen > /dev/null; then
|
||||||
echo "screen not found – installing"
|
echo "screen not found – installing"
|
||||||
apt-get update && apt-get install -y screen
|
apt-get update && apt-get install -y screen
|
||||||
fi
|
fi
|
||||||
EOF
|
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 \
|
||||||
-o ServerAliveInterval=60 \
|
-o ServerAliveInterval=60 \
|
||||||
-o ServerAliveCountMax=120 \
|
-o ServerAliveCountMax=120 \
|
||||||
root@${params.host_ip} <<'EOF'
|
root@${params.host_ip} <<'EOF'
|
||||||
# Start test in detached screen
|
# Start test in detached screen
|
||||||
screen -dmS ${env.SCREEN_SESSION} bash -c '
|
screen -dmS ${env.SCREEN_SESSION} bash -c '
|
||||||
echo "===== BLE test starting: $(date)" > /tmp/ble_test.log
|
echo "===== BLE test starting: \$(date)" > /tmp/ble_test.log
|
||||||
usbreset ${params.BT_USB_ID}
|
usbreset ${params.BT_USB_ID}
|
||||||
sleep 5
|
sleep 5
|
||||||
cd /opt/ble-test/ble_api
|
cd /opt/ble-test/ble_api
|
||||||
git pull
|
git pull
|
||||||
cd /opt/ble-test/ble_api/api
|
cd /opt/ble-test/ble_api/api
|
||||||
python3 -u ${REMOTE_SCRIPT} ${params.test_count} 2>&1 | tee -a /tmp/ble_test.log
|
python3 -u ${REMOTE_SCRIPT} ${params.test_count} 2>&1 | tee -a /tmp/ble_test.log
|
||||||
echo "===== BLE test finished: $(date)" >> /tmp/ble_test.log
|
echo "===== BLE test finished: \$(date)" >> /tmp/ble_test.log
|
||||||
'
|
'
|
||||||
# Give screen a moment to spin up
|
# Give screen a moment to spin up
|
||||||
sleep 2
|
sleep 2
|
||||||
EOF
|
EOF
|
||||||
'''
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// 3a. Verify that the test finished successfully
|
// 3a. Verify that the test finished successfully
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
sh '''\
|
sh """
|
||||||
ssh -o StrictHostKeyChecking=no \
|
ssh -o StrictHostKeyChecking=no \
|
||||||
-o ServerAliveInterval=60 \
|
-o ServerAliveInterval=60 \
|
||||||
-o ServerAliveCountMax=120 \
|
-o ServerAliveCountMax=120 \
|
||||||
root@${params.host_ip} <<'EOF'
|
root@${params.host_ip} <<'EOF'
|
||||||
if grep -q "BLE test finished" /tmp/ble_test.log; then
|
if grep -q "BLE test finished" /tmp/ble_test.log; then
|
||||||
echo "Test completed successfully."
|
echo "Test completed successfully."
|
||||||
else
|
else
|
||||||
echo "Test did NOT finish – aborting build."
|
echo "Test did NOT finish – aborting build."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EOF
|
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 \
|
||||||
-o ServerAliveInterval=60 \
|
-o ServerAliveInterval=60 \
|
||||||
-o ServerAliveCountMax=120 \
|
-o ServerAliveCountMax=120 \
|
||||||
root@${params.host_ip} <<'EOF'
|
root@${params.host_ip} <<'EOF'
|
||||||
if screen -list | grep -q ${env.SCREEN_SESSION}; then
|
if screen -list | grep -q ${env.SCREEN_SESSION}; then
|
||||||
screen -S ${env.SCREEN_SESSION} -X quit
|
screen -S ${env.SCREEN_SESSION} -X quit
|
||||||
fi
|
fi
|
||||||
EOF
|
EOF
|
||||||
'''
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user