mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-31 08:28:34 +00:00
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:
@@ -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}" \
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user