Skip to content

Commit 4b278fe

Browse files
Jenkins in a loop (commaai#34582)
* loop * better * clean * more * fix
1 parent d1b9328 commit 4b278fe

File tree

2 files changed

+147
-2
lines changed

2 files changed

+147
-2
lines changed

Jenkinsfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def deviceStage(String stageName, String deviceType, List extra_env, def steps)
103103
def diffPaths = args.diffPaths ?: []
104104
def cmdTimeout = args.timeout ?: 9999
105105

106-
if (branch != "master" && diffPaths && !hasPathChanged(gitDiff, diffPaths)) {
106+
if (branch != "master" && !branch.contains("__jenkins_loop_") && diffPaths && !hasPathChanged(gitDiff, diffPaths)) {
107107
println "Skipping ${name}: no changes in ${diffPaths}."
108108
return
109109
} else {
@@ -170,7 +170,7 @@ node {
170170
'testing-closet*', 'hotfix-*']
171171
def excludeRegex = excludeBranches.join('|').replaceAll('\\*', '.*')
172172

173-
if (env.BRANCH_NAME != 'master') {
173+
if (env.BRANCH_NAME != 'master' && !env.BRANCH_NAME.contains('__jenkins_loop_')) {
174174
properties([
175175
disableConcurrentBuilds(abortPrevious: true)
176176
])

scripts/jenkins_loop_test.sh

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
YELLOW='\033[0;33m'
5+
GREEN='\033[0;32m'
6+
UNDERLINE='\033[4m'
7+
BOLD='\033[1m'
8+
NC='\033[0m'
9+
10+
BRANCH="master"
11+
RUNS="20"
12+
13+
COOKIE_JAR=/tmp/cookies
14+
CRUMB=$(curl -s --cookie-jar $COOKIE_JAR 'https://jenkins.comma.life/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
15+
16+
function loop() {
17+
JENKINS_BRANCH="__jenkins_loop_${BRANCH}"
18+
API_ROUTE="https://jenkins.comma.life/job/openpilot/job/$JENKINS_BRANCH"
19+
20+
for run in $(seq 1 $((RUNS / 2))); do
21+
22+
N=2
23+
TEST_BUILDS=()
24+
25+
# Try to find previous builds
26+
ALL_BUILDS=( $(curl -s $API_ROUTE/api/json | jq .builds.[].number 2> /dev/null || :) )
27+
28+
# No builds. Create branch
29+
if [[ ${#ALL_BUILDS[@]} -eq 0 ]]; then
30+
TEMP_DIR=$(mktemp -d)
31+
GIT_LFS_SKIP_SMUDGE=1 git clone --quiet -b $BRANCH --depth=1 --no-tags [email protected]:commaai/openpilot $TEMP_DIR
32+
git -C $TEMP_DIR checkout --quiet -b $JENKINS_BRANCH
33+
echo "TESTING" >> $TEMP_DIR/testing_jenkins
34+
git -C $TEMP_DIR add testing_jenkins
35+
git -C $TEMP_DIR commit --quiet -m "testing"
36+
git -C $TEMP_DIR push --quiet -f origin $JENKINS_BRANCH
37+
rm -rf $TEMP_DIR
38+
FIRST_BUILD=1
39+
echo ''
40+
echo 'waiting on Jenkins...'
41+
echo ''
42+
sleep 90
43+
else
44+
# Found some builds. Wait for them to end if they are still running
45+
for i in ${ALL_BUILDS[@]}; do
46+
running=$(curl -s $API_ROUTE/$i/api/json/ | jq .inProgress)
47+
if [[ $running == "false" ]]; then
48+
continue
49+
fi
50+
TEST_BUILDS=( ${ALL_BUILDS[@]} )
51+
N=${#TEST_BUILDS[@]}
52+
break
53+
done
54+
fi
55+
56+
# No running builds found
57+
if [[ ${#TEST_BUILDS[@]} -eq 0 ]]; then
58+
FIRST_BUILD=$(curl -s $API_ROUTE/api/json | jq .nextBuildNumber)
59+
LAST_BUILD=$((FIRST_BUILD+N-1))
60+
TEST_BUILDS=( $(seq $FIRST_BUILD $LAST_BUILD) )
61+
62+
# Start N new builds
63+
for i in ${TEST_BUILDS[@]};
64+
do
65+
echo "Starting build $i"
66+
curl -s --output /dev/null --cookie $COOKIE_JAR -H "$CRUMB" -X POST $API_ROUTE/build?delay=0sec
67+
sleep 5
68+
done
69+
echo ""
70+
fi
71+
72+
# Wait for all builds to end
73+
while true; do
74+
sleep 30
75+
76+
count=0
77+
for i in ${TEST_BUILDS[@]};
78+
do
79+
RES=$(curl -s -w "\n%{http_code}" --cookie $COOKIE_JAR -H "$CRUMB" $API_ROUTE/$i/api/json)
80+
HTTP_CODE=$(tail -n1 <<< "$RES")
81+
JSON=$(sed '$ d' <<< "$RES")
82+
83+
if [[ $HTTP_CODE == "200" ]]; then
84+
STILL_RUNNING=$(echo $JSON | jq .inProgress)
85+
if [[ $STILL_RUNNING == "true" ]]; then
86+
echo -e "Build $i: ${YELLOW}still running${NC}"
87+
continue
88+
else
89+
count=$((count+1))
90+
echo -e "Build $i: ${GREEN}done${NC}"
91+
fi
92+
else
93+
echo "No status for build $i"
94+
fi
95+
done
96+
echo "See live results: ${API_ROUTE}/buildTimeTrend"
97+
echo ""
98+
99+
if [[ $count -ge $N ]]; then
100+
break
101+
fi
102+
done
103+
104+
done
105+
}
106+
107+
function usage() {
108+
echo ""
109+
echo "Run the Jenkins tests multiple times on a specific branch"
110+
echo ""
111+
echo -e "${BOLD}${UNDERLINE}Options:${NC}"
112+
echo -e " ${BOLD}-n, --n${NC}"
113+
echo -e " Specify how many runs to do (default to ${BOLD}20${NC})"
114+
echo -e " ${BOLD}-b, --branch${NC}"
115+
echo -e " Specify which branch to run the tests against (default to ${BOLD}master${NC})"
116+
echo ""
117+
}
118+
119+
function _looper() {
120+
if [[ $# -eq 0 ]]; then
121+
usage
122+
exit 0
123+
fi
124+
125+
# parse Options
126+
while [[ $# -gt 0 ]]; do
127+
case $1 in
128+
-n | --n ) shift 1; RUNS="$1"; shift 1 ;;
129+
-b | --b | --branch | -branch ) shift 1; BRANCH="$1"; shift 1 ;;
130+
* ) usage; exit 0 ;;
131+
esac
132+
done
133+
134+
echo ""
135+
echo -e "You are about to start $RUNS Jenkins builds against the $BRANCH branch."
136+
echo -e "If you expect this to run overnight, ${UNDERLINE}${BOLD}unplug the cold reboot power switch${NC} from the testing closet before."
137+
echo ""
138+
read -p "Press (y/Y) to confirm: " choice
139+
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
140+
loop
141+
fi
142+
143+
}
144+
145+
_looper $@

0 commit comments

Comments
 (0)