- # Wait until a line appears in the screen session
- local T=${2:-10s}
- timeout -k 3s ${T} grep -q "^${1}" <(tail -f screenlog.0)
+ # Wait until a line appears in the screen session.
+ # It starts from the beginning of the log and exits after the first match.
+ local T=${2:-20s}
+ #timeout -k 3s ${T} stdbuf -o0 grep -q -m 1 "^${1}" <(tail -F -n+0 screenlog.0)
+ # (HACK) As Jenkins blocks subshell, we must use an intermediate script
+ local SUBF=$(mktemp)
+ chmod +x ${SUBF}
+ cat > ${SUBF} <<- EOF
+ #!/bin/bash -e
+ while true; do
+ if strings screenlog.0 | grep -m 1 "\${1}"; then
+ exit 0
+ fi
+ sleep 0.5s
+ done
+ EOF
+ local RES=0
+ timeout -k 3s ${T} ${SUBF} "${1}" || RES=$?
+ rm -f ${SUBF}
+ if [ ! "$RES" = "0" ]; then
+ sync
+ echo -e "\n\n\n(Debug) Error while waiting for a pattern to appear in screenlog.0\n\n\n"
+ strings screenlog.0
+ fi
+ return ${RES}