diff --git a/Jenkinsfile b/Jenkinsfile index 4962c2b..22f0afd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -88,14 +88,28 @@ pipeline { "\$@" >"\$log_file" 2>&1 & cmd_pid=\$! cmd_status=0 - tail --pid="\$cmd_pid" -n +1 -f "\$log_file" & - tail_pid=\$! + last_line=0 while kill -0 "\$cmd_pid" >/dev/null 2>&1; do - echo "[heartbeat] API multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if [ -f "\$log_file" ]; then + total_lines=\$(wc -l < "\$log_file" 2>/dev/null || echo 0) + else + total_lines=0 + fi + if [ "\$total_lines" -gt "\$last_line" ]; then + sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file" + last_line=\$total_lines + else + echo "[heartbeat] API multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)" + fi sleep 20 done wait "\$cmd_pid" || cmd_status=\$? - wait "\$tail_pid" >/dev/null 2>&1 || true + if [ -f "\$log_file" ]; then + total_lines=\$(wc -l < "\$log_file" 2>/dev/null || echo 0) + if [ "\$total_lines" -gt "\$last_line" ]; then + sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file" + fi + fi if [ "\$cmd_status" -ne 0 ]; then echo "[heartbeat] API multi-arch build failed with exit code \$cmd_status" fi @@ -150,14 +164,28 @@ pipeline { "\$@" >"\$log_file" 2>&1 & cmd_pid=\$! cmd_status=0 - tail --pid="\$cmd_pid" -n +1 -f "\$log_file" & - tail_pid=\$! + last_line=0 while kill -0 "\$cmd_pid" >/dev/null 2>&1; do - echo "[heartbeat] Web multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)" + if [ -f "\$log_file" ]; then + total_lines=\$(wc -l < "\$log_file" 2>/dev/null || echo 0) + else + total_lines=0 + fi + if [ "\$total_lines" -gt "\$last_line" ]; then + sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file" + last_line=\$total_lines + else + echo "[heartbeat] Web multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)" + fi sleep 20 done wait "\$cmd_pid" || cmd_status=\$? - wait "\$tail_pid" >/dev/null 2>&1 || true + if [ -f "\$log_file" ]; then + total_lines=\$(wc -l < "\$log_file" 2>/dev/null || echo 0) + if [ "\$total_lines" -gt "\$last_line" ]; then + sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file" + fi + fi if [ "\$cmd_status" -ne 0 ]; then echo "[heartbeat] Web multi-arch build failed with exit code \$cmd_status" fi