add loop breaker to test 2
This commit is contained in:
1 parent
0b4bb35962
commit
44fa740532
2 files changed
+59
-28
No files matched your search
+58
-27
@@ -1,46 +1,77 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// Global environment variables – change as needed
|
||||||
|
// ------------------------------------------------------------------
|
||||||
environment {
|
environment {
|
||||||
DEBIAN_IP = 'debian_machine_ip'
|
DEBIAN_IP = 'debian_machine_ip'
|
||||||
SSH_CREDENTIALS_ID = 'jenkins_root_ssh'
|
SSH_CREDENTIALS_ID = 'jenkins_root_ssh'
|
||||||
REMOTE_SCRIPT = '/opt/ble-test/ble_api/api/ble.py'
|
REMOTE_SCRIPT = '/opt/ble-test/ble_api/api/ble.py'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// Build parameters (visible to the user)
|
||||||
|
// ------------------------------------------------------------------
|
||||||
parameters {
|
parameters {
|
||||||
string(name: 'host_ip', defaultValue: '172.20.20.51', description: 'IP of the host that runs the BLE test')
|
string(name: 'host_ip', defaultValue: '', description: 'IP of the host that runs the BLE test')
|
||||||
string(name: 'test_count', defaultValue: '25', description: 'Number of test iterations')
|
string(name: 'test_count', defaultValue: '1000', description: 'Number of test iterations')
|
||||||
string(name: 'BT_USB_ID', defaultValue: '0bda:c821', description: 'USB ID of the BLE dongle')
|
string(name: 'BT_USB_ID', defaultValue: '0001', description: 'USB ID of the BLE dongle')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// Stages
|
||||||
|
// ------------------------------------------------------------------
|
||||||
stages {
|
stages {
|
||||||
stage('Run BLE Test') {
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 1️⃣ Prepare a unique screen session name
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
stage('Prepare Screen Name') {
|
||||||
steps {
|
steps {
|
||||||
// ----- 1. Compute a 6‑digit hash from the epoch seconds
|
|
||||||
script {
|
script {
|
||||||
// epoch seconds at the moment the build starts
|
// epoch seconds truncated to the last 6 digits
|
||||||
def epochSec = System.currentTimeMillis() / 1000
|
def epochSec = System.currentTimeMillis() / 1000
|
||||||
// keep only the last 6 decimal digits
|
env.SCREEN_SESSION = "ble_test_${String.format('%06d', epochSec % 1_000_000)}"
|
||||||
def hash = String.format("%06d", epochSec % 1_000_000)
|
}
|
||||||
env.SCREEN_SESSION = "ble_test_${hash}"
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----- 2. Retry SSH 3× in case of a transient hiccup
|
// ---------------------------------------------------------------
|
||||||
retry(3) {
|
// 2️⃣ Verify / install screen (runs only once)
|
||||||
// ----- 3. Timeout the whole test (adjust as needed)
|
// ---------------------------------------------------------------
|
||||||
timeout(time: 5, unit: 'MINUTES') {
|
stage('Ensure screen is present') {
|
||||||
|
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'
|
||||||
# Ensure screen is present
|
# If screen is missing, install it
|
||||||
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
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
// 3️⃣ Run the BLE test in a detached screen session
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
stage('Run BLE Test') {
|
||||||
|
steps {
|
||||||
|
retry(3) {
|
||||||
|
timeout(time: 8, unit: 'HOURS') {
|
||||||
|
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
|
# Start the test in a detached screen session
|
||||||
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
|
||||||
@@ -52,17 +83,13 @@ pipeline {
|
|||||||
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
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small pause so the screen session has a chance to start
|
// Verify that the test finished
|
||||||
sh 'sleep 2'
|
|
||||||
|
|
||||||
// Verify that the test reported completion
|
|
||||||
sh """
|
sh """
|
||||||
ssh -o StrictHostKeyChecking=no \\
|
ssh -o StrictHostKeyChecking=no \\
|
||||||
-o ServerAliveInterval=60 \\
|
-o ServerAliveInterval=60 \\
|
||||||
@@ -71,20 +98,23 @@ pipeline {
|
|||||||
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
|
||||||
"""
|
"""
|
||||||
} // end timeout
|
}
|
||||||
} // end retry
|
}
|
||||||
} // end steps
|
}
|
||||||
} // end stage
|
}
|
||||||
} // end stages
|
}
|
||||||
|
|
||||||
// ----- 4. Clean up the screen session on the remote host
|
// ------------------------------------------------------------------
|
||||||
|
// Post‑build cleanup – kill the remote screen session
|
||||||
|
// ------------------------------------------------------------------
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
sshagent([env.SSH_CREDENTIALS_ID]) {
|
||||||
sh """
|
sh """
|
||||||
ssh -o StrictHostKeyChecking=no \\
|
ssh -o StrictHostKeyChecking=no \\
|
||||||
-o ServerAliveInterval=60 \\
|
-o ServerAliveInterval=60 \\
|
||||||
@@ -98,3 +128,4 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -291,7 +291,7 @@ def test(test_count = 0, bt_usb_id = None) -> None:
|
|||||||
log.info(f" Scanning MACs: {mac_list}")
|
log.info(f" Scanning MACs: {mac_list}")
|
||||||
test_list = mac_list
|
test_list = mac_list
|
||||||
while not test_result:
|
while not test_result:
|
||||||
if test_count > 20:
|
if test_loop_count > 20:
|
||||||
reset_adapter()
|
reset_adapter()
|
||||||
reset_count = reset_count + 1
|
reset_count = reset_count + 1
|
||||||
test_loop_count = 0
|
test_loop_count = 0
|
||||||
|
|||||||
Reference in new issue
Block a user