Skip to content

Commit 2093a1e

Browse files
all
1 parent fde1ff2 commit 2093a1e

File tree

1 file changed

+88
-61
lines changed

1 file changed

+88
-61
lines changed

Jenkinsfile

+88-61
Original file line numberDiff line numberDiff line change
@@ -172,68 +172,95 @@ node {
172172

173173
if (env.BRANCH_NAME == 'jenkins_stress_NOT_NOW') {
174174
sh '''#!/bin/bash
175-
176-
# get crumb for CSRF
177-
COOKIE_JAR=/tmp/cookies
178-
CRUMB=$(curl --cookie-jar $COOKIE_JAR 'https://jenkins.comma.life/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
179-
180-
N=5
181-
FIRST_RUN=$(curl --cookie $COOKIE_JAR -H "$CRUMB" https://jenkins.comma.life/job/openpilot/job/__jenkins_stress/api/json | jq .nextBuildNumber)
182-
LAST_RUN=$((FIRST_RUN+N))
183-
184-
for i in $(seq $FIRST_RUN $LAST_RUN);
185-
do
186-
# start build i
187-
curl --output /dev/null --cookie $COOKIE_JAR -H "$CRUMB" -X POST https://jenkins.comma.life/job/openpilot/job/__jenkins_stress/build?delay=0sec
188-
done
189-
190-
while true; do
191-
sleep 5
192-
193-
count=0
194-
FAIL=()
195-
PASS=()
196-
197-
for i in $(seq $FIRST_RUN $LAST_RUN);
198-
do
199-
RES=$(curl -s -w "\n%{http_code}" --cookie $COOKIE_JAR -H "$CRUMB" https://jenkins.comma.life/job/openpilot/job/__jenkins_stress/$i/api/json)
200-
HTTP_CODE=$(tail -n1 <<< "$RES")
201-
JSON=$(sed '$ d' <<< "$RES")
202-
203-
if [[ $HTTP_CODE == "200" ]]; then
204-
STILL_RUNNING=$(echo $JSON | jq .inProgress)
205-
if [[ $STILL_RUNNING == "true" ]]; then
206-
echo "build $i still running"
207-
continue
208-
fi
209-
210-
RESULT=$(echo $JSON | jq .result)
211-
((count++))
212-
echo "build $i $RESULT"
213-
214-
if [[ $RESULT == '"SUCCESS"' ]]; then
215-
PASS+=($i)
216-
elif [[ $RESULT == '"FAILURE"' ]]; then
217-
FAIL+=($i)
218-
elif [[ $RESULT == '"ABORTED"' ]]; then
219-
FAIL+=($i)
220-
else
221-
FAIL+=($i)
222-
fi
223-
224-
else
225-
echo "Error getting status of build $i"
226-
fi
227-
228-
done
229-
230-
if [[ $count -eq $N ]]; then
231-
echo "FAIL : ${FAIL[@]}"
232-
echo "PASS : ${PASS[@]}"
233-
break
175+
# get crumb for CSRF
176+
COOKIE_JAR=/tmp/cookies
177+
CRUMB=$(curl --cookie-jar $COOKIE_JAR 'https://jenkins.comma.life/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
178+
179+
N=5
180+
FIRST_RUN=$(curl --cookie $COOKIE_JAR -H "$CRUMB" https://jenkins.comma.life/job/openpilot/job/jenkins_test_runner/api/json | jq .nextBuildNumber)
181+
LAST_RUN=$((FIRST_RUN+N))
182+
183+
for i in $(seq $FIRST_RUN $LAST_RUN);
184+
do
185+
# start build i
186+
curl --output /dev/null --cookie $COOKIE_JAR -H "$CRUMB" -X POST https://jenkins.comma.life/job/openpilot/job/jenkins_test_runner/build?delay=0sec
187+
done
188+
189+
while true; do
190+
sleep 60
191+
192+
count=0
193+
for i in $(seq $FIRST_RUN $LAST_RUN);
194+
do
195+
RES=$(curl -s -w "\n%{http_code}" --cookie $COOKIE_JAR -H "$CRUMB" https://jenkins.comma.life/job/openpilot/job/jenkins_test_runner/$i/api/json)
196+
HTTP_CODE=$(tail -n1 <<< "$RES")
197+
JSON=$(sed '$ d' <<< "$RES")
198+
199+
if [[ $HTTP_CODE == "200" ]]; then
200+
STILL_RUNNING=$(echo $JSON | jq .inProgress)
201+
if [[ $STILL_RUNNING == "true" ]]; then
202+
echo "build $i still running"
203+
continue
234204
fi
235-
236-
done
205+
((count++))
206+
else
207+
echo "Error getting status of build $i"
208+
fi
209+
done
210+
211+
if [[ $count -eq $N ]]; then
212+
break
213+
fi
214+
done
215+
216+
217+
STAGES_NAMES=()
218+
while read stage; do
219+
STAGES_NAMES[$index]=$stage
220+
((index++))
221+
done < <(curl -s -H "$CRUMB" https://jenkins.comma.life/job/openpilot/job/jenkins_test_runner/lastBuild/wfapi/ | jq .stages[].name)
222+
STAGES_COUNT=${#STAGES_NAMES[@]}
223+
224+
STAGES_FAILURES=($(for i in $(seq 1 $STAGES_COUNT); do echo 0; done))
225+
STAGES_FAILURES_LOGS=()
226+
227+
for i in $(seq $FIRST_RUN $LAST_RUN);
228+
do
229+
230+
index=0
231+
while read result; do
232+
if [[ $result != '"SUCCESS"' ]]; then
233+
STAGES_FAILURES[$index]=$((STAGES_FAILURES[$index]+1))
234+
STAGES_FAILURES_LOGS[$index]="${STAGES_FAILURES_LOGS[$index]}<a href=\"https://jenkins.comma.life/blue/organizations/jenkins/openpilot/detail/jenkins_test_runner/$i/pipeline/\">Log for run #$(($i-$FIRST_RUN))</a><br>"
235+
fi
236+
((index++))
237+
done < <(curl https://jenkins.comma.life/job/openpilot/job/jenkins_test_runner/$i/wfapi/ | jq .stages[].status)
238+
239+
done
240+
241+
TABLE="<table><thead><tr> <th>Stage</th> <th>✅ Passing</th> <th>❌ Failure Details</th> </tr></thead><tbody>"
242+
for i in $(seq 0 $(($STAGES_COUNT-1)));
243+
do
244+
TABLE="${TABLE}<tr>"
245+
TABLE="${TABLE}<td>${STAGES_NAMES[$i]}</td>"
246+
TABLE="${TABLE}<td>$((100-(${STAGES_FAILURES[$i]}*100/$N)))%</td>"
247+
if [[ ${STAGES_FAILURES[$i]} -eq 0 ]]; then
248+
TABLE="${TABLE}<td></td>"
249+
else
250+
TABLE="${TABLE}<td><details>${STAGES_FAILURES_LOGS[$i]}</details></td>"
251+
fi
252+
TABLE="${TABLE}</tr>"
253+
done
254+
TABLE="${TABLE}</table>"
255+
256+
git clone -b master --depth=1 https://github.com/commaai/ci-artifacts
257+
cd ci-artifacts
258+
git checkout -b "jenkins_test_report"
259+
echo "$TABLE" >> jenkins_report
260+
git add jenkins_report
261+
git commit -m "jenkins report"
262+
git remote set-url origin https://${env.CI_ARTIFACTS_TOKEN}@github.com/commaai/ci-artifacts.git
263+
git push -f origin jenkins_test_report
237264
'''
238265

239266
currentBuild.result = 'SUCCESS'

0 commit comments

Comments
 (0)