- # 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
+ set -x
+ while true; do
+ if strings screenlog.0 | grep -m 1 "\${1}"; then
+ exit 0
+ fi
+ sleep 0.5s
+ done
+ EOF
+ cat ${SUBF}
+ timeout -k 3s ${T} ${SUBF} "${1}"
+ local RES=$?
+ rm -f ${SUBF}
+ return ${RES}