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