-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.sh
More file actions
43 lines (37 loc) · 1.6 KB
/
bash.sh
File metadata and controls
43 lines (37 loc) · 1.6 KB
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
#!/bin/sh
sonar_token=$1
sonar_server=$2
#take care for the line where is ceTaskId info in the file /.scannerwork/report-task.txt;
#It changes depending of server and sonar scanner version, in my case is at line 7
ceTaskId=$(head -7 $3 | tail -1)
taskId=$(echo "$ceTaskId" | cut -d'=' -f 3)
## Checking for the request server status.
STATUS=$(curl -u $sonar_token: -s -o /dev/null -w '%{http_code}' http://$sonar_server/api/ce/task?id=$taskId)
echo $STATUS
if [ $STATUS != 200 ]
then
echo "Was imposible to connect to the server (https://$sonar_server/api/ce/task?id=$taskId)"
exit 1
fi
taskStatus=$(curl -u $sonar_token: http://$sonar_server/api/ce/task?id=$taskId | jq -r .task.status)
while [ "$taskStatus" = "PENDING" ] || [ "$taskStatus" = "IN_PROGRESS" ]
do
clear
echo "Task $taskId status is: $taskStatus, new retry in 5 seconds"
sleep 5
taskStatus=$(curl -u $sonar_token: http://$sonar_server/api/ce/task?id=$taskId | jq -r .task.status)
done
if [ "$taskStatus" = "SUCCESS" ]
then
analysisId=$(curl -u $sonar_token: http://$sonar_server/api/ce/task?id=$taskId | jq -r .task.analysisId)
quality_gatesstatus=$(curl -u $sonar_token: http://$sonar_server/api/qualitygates/project_status?analysisId=$analysisId | jq -r .projectStatus.status)
else
echo "The analysis was not SUCCESS, it was $taskStatus"
exit 1
fi
echo "the Sonar quality gates for current analysis was: $quality_gatesstatus"
if [ "$quality_gatesstatus" != "OK" ] && [ "$quality_gatesstatus" != "WARN" ]
then
echo "check sonar server and fix the issues"
exit 1
fi