obs: wait: Fix error to detect building job

The job to wait for packages are built is failing randomly.

Seems that sometimes the command is not returning and expected
out out and may be mask by the

`while osc pr | grep; done`

This probably can fail at osc pr but because it failed at
osc and not grep we consider is working.

- We check for more states that we consider not ready,
like excluded or blocked.

First query the result, if fail the script will stop,
if not then try to find the string `state=building`.

Additionally, check for failed jobs in the same query to
stop the job earlier.

Fixes: #665

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
This commit is contained in:
Jose Carlos Venegas Munoz
2019-08-05 12:57:51 -05:00
parent 72321d298f
commit 3ba0d65272
2 changed files with 51 additions and 23 deletions

View File

@@ -27,7 +27,7 @@ user = ${OBS_USER}
pass = ${OBS_PASS}
eom
fi
) >> /dev/null
) >>/dev/null
if [ ! -e "${OSCRC}" ]; then
echo "${OSCRC}, please do 'export OBS_USER=your_user ; export OBS_PASS=your_pass' to configure osc for first time."
exit 1
@@ -56,6 +56,7 @@ docker_run() {
--env GO_ARCH="${GO_ARCH}" \
--env PUSH="${PUSH:-}" \
--env DEBUG="${DEBUG:-}" \
--env OBS_PROJECT="${OBS_PROJECT:-}" \
--env OBS_SUBPROJECT="${OBS_SUBPROJECT:-}" \
-v "${cache_dir}":/var/tmp/osbuild-packagecache/ \
-v "${_obs_docker_packaging_repo_dir}":"${_obs_docker_packaging_repo_dir}" \

View File

@@ -11,6 +11,10 @@ set -o errtrace
script_name="$(basename "${BASH_SOURCE[0]}")"
OBS_PROJECT=${OBS_PROJECT:-"home:katacontainers:"}
# Project to wait for
project=""
handle_error() {
local exit_code="${?}"
local line_number="${1:-}"
@@ -31,12 +35,33 @@ run_in_docker() {
fi
}
# Check all project has finshed the build
wait_finish_building() {
while osc pr -q | grep '(building)'; do sleep 5; done
# just in case something goes wrong
while osc pr -q | grep '(building)'; do sleep 5; done
local out
while true; do
sleep 10
out=$(osc api "/build/${project}/_result")
if echo "${out}" | grep '<details>failed</details>'; then
echo "Project ${project} has failed packages"
osc pr
exit 1
fi
if echo "${out}" | grep 'code="blocked"'; then
echo "Project ${project} has blocked packages, waiting"
continue
fi
if echo "${out}" | grep 'code="excluded"'; then
echo "Project ${project} has excluded packages, waiting"
continue
fi
if echo "${out}" | grep 'state="building"'; then
echo "Project ${project} is still building, waiting"
continue
fi
echo "No jobs with building status were found"
echo "${out}"
break
done
}
# obs distro final status is 'published'
@@ -63,10 +88,9 @@ wait_published() {
done
}
check_failed(){
failed_query=$(osc pr -c -s F)
regex=".*failed.*"
if [[ ${failed_query} =~ ${regex} ]];then
check_failed() {
failed_query=$(osc pr -c -s F)
if [[ ${failed_query} =~ failed ]]; then
echo "ERROR: Build failed"
osc pr -V -s 'F'
exit 1
@@ -92,22 +116,25 @@ EOT
}
main() {
run_in_docker $@
run_in_docker $@
local no_wait_publish="false"
case "${1:-}" in
"-h"|"--help")
usage "Help" 0
;;
--no-wait-publish)
no_wait_publish="true"
shift
;;
-*)
usage "Invalid option: ${1:-}" 1
;;
"-h" | "--help")
usage "Help" 0
;;
--no-wait-publish)
no_wait_publish="true"
shift
;;
-*)
usage "Invalid option: ${1:-}" 1
;;
esac
OBS_SUBPROJECT="${OBS_SUBPROJECT:-releases:x86_64:alpha}"
project="home:katacontainers:${OBS_SUBPROJECT}"
project=${1:-}
if [ "${project}" == "" ]; then
OBS_SUBPROJECT="${OBS_SUBPROJECT:-}"
project="${OBS_PROJECT}${OBS_SUBPROJECT}"
fi
echo "Checkout: ${project}"
osc co "$project" || true
cd "$project" || exit 1
@@ -120,7 +147,7 @@ main() {
check_failed
echo "OK - build did not fail"
if [ "${no_wait_publish}" == "true" ];then
if [ "${no_wait_publish}" == "true" ]; then
echo " Requested not wait for publish"
exit
fi