-
Notifications
You must be signed in to change notification settings - Fork 22
/
monitor-openqa_job
executable file
·61 lines (52 loc) · 2.33 KB
/
monitor-openqa_job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash -ex
# Monitor an openQA job by polling the status of a job over the API.
#
# Continuously polls the openQA API for the status of the specified jobs until
# all jobs finish. After the jobs have finished this program exits with an exit
# code corresponding to the jobs' result. For example all jobs pass it would exit
# this program with exit code 0 for success; otherwise with 1.
set -euo pipefail
# configuration variables with defaults.
sleep_time="${sleep_time:-"10"}"
openqa_cli="${openqa_cli:-"openqa-cli"}"
host="${host:-"https://openqa.opensuse.org"}"
openqa_groupid="${openqa_groupid:-"24"}"
obs_component="${obs_component:-"package"}"
obs_package_name="${1:-""}"
staging_project=${staging_project:-devel:openQA:testing}
comment_on_obs=${comment_on_obs:-}
# shellcheck source=/dev/null
. "$(dirname "$0")"/_common
[[ -f job_post_response ]] || (echo "Need job response status file 'job_post_response'" && exit 2)
declare -A failed_versions
failed_jobs=()
for job_id in $(job_ids job_post_response); do
echo "Waiting for job $job_id to finish"
while sleep "${sleep_time}"; do
job_state=$($openqa_cli api --host "$host" jobs/"$job_id" | jq -r '.job.state')
[[ $job_state = 'done' ]] && break
done
response=$($openqa_cli api --host "$host" jobs/"$job_id")
result=$(echo "$response" | jq -r '.job.result')
echo "Result of job $job_id: $result"
if [[ $result != 'passed' ]] && [[ -n $obs_package_name ]]; then
version=$(echo "$response" | jq -r '.job.settings.VERSION')
failed_versions[$version]=1
failed_jobs+=("$job_id")
fi
done
[[ ${failed_jobs[*]} ]] || exit 0
# delete packages from staging project in error case as we will not continue submitting those packages
delete_packages_from_obs_project "$staging_project"
# comment on failed jobs
[[ $comment_on_obs ]] || exit 1
osc api "/comments/$obs_component/$obs_package_name" | grep id= | sed -n 's/.*id="\([^"]*\)">.*test.* failed.*/\1/p' | while read -r id; do
osc api -X DELETE /comment/"$id"
done
comment="openQA-in-openQA test(s) failed (job IDs: ${failed_jobs[*]}), see https://openqa.opensuse.org/tests/overview?"
for version in "${!failed_versions[@]}"; do
comment+="version=${version}&"
done
comment+="groupid=$openqa_groupid"
osc api --data="$comment" -X POST "/comments/${obs_component}/$obs_package_name"
exit 1