Skip to content

job count mismatch by 1

This is our control loop

while sleep 20s; do
    JOBS=$(curl -s http://localhost:9402/debug/jobs/list | wc -l)
    if [[ "${JOBS}" == "0" ]]; then
        break
    fi

    echo "$(date --rfc-3339=seconds): ${JOBS} running jobs on ${HOSTNAME}..."
done &

echo Signal stop of build processing...
sudo gitlab-runner stop

The problem is that wc -l counts \n and http://localhost:9402/debug/jobs/list is not new-line terminated, this gives an offset by 1 in our counting.

# echo -n "test" | wc -l
0
# echo "test" | wc -l
1

/cc @tmaczukin