-
Notifications
You must be signed in to change notification settings - Fork 362
/
Jenkinsfile
186 lines (180 loc) · 7.14 KB
/
Jenkinsfile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env groovy
String CARLA_HOST
String CARLA_RELEASE
String TEST_HOST
String COMMIT
String ECR_REPOSITORY = "456841689987.dkr.ecr.eu-west-3.amazonaws.com/scenario_runner"
boolean CARLA_RUNNING = false
boolean CONCURRENCY = true
// V3 - include detection of concurrent builds
pipeline
{
agent none
options
{
buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3'))
skipDefaultCheckout()
}
stages
{
stage('setup')
{
agent { label "master" }
steps
{
checkout scm
script
{
jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
TEST_HOST = jenkinsLib.getUbuntuTestNodeHost()
CARLA_HOST= sh(
script: "cat ./CARLA_VER | grep HOST | sed 's/HOST\\s*=\\s*//g'",
returnStdout: true).trim()
CARLA_RELEASE = sh(
script: "cat ./CARLA_VER | grep RELEASE | sed 's/RELEASE\\s*=\\s*//g'",
returnStdout: true).trim()
COMMIT = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
}
println "using CARLA version ${CARLA_RELEASE} from ${TEST_HOST}"
}
}
stage('get concurrency status')
{
options
{
lock resource: 'ubuntu_gpu', skipIfLocked: true
}
agent { label "master" }
steps
{
script
{
CONCURRENCY = false
println "no concurrent builds detected."
}
}
}
stage('act on concurrency')
{
agent { label "master" }
steps
{
script
{
if ( CONCURRENCY == true )
{
println "concurrent builds detected, prebuilding SR image."
stage('prebuild SR docker image')
{
//checkout scm
sh "docker build -t jenkins/scenario_runner:${COMMIT} ."
sh "docker tag jenkins/scenario_runner:${COMMIT} ${ECR_REPOSITORY}:${COMMIT}"
sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
sh "docker push ${ECR_REPOSITORY}"
sh "docker image rmi -f \"\$(docker images -q ${ECR_REPOSITORY}:${COMMIT})\""
}
}
}
}
}
stage('lock ubuntu_gpu instance')
{
options
{
lock resource: "ubuntu_gpu"
}
stages
{
stage('start server')
{
agent { label "master" }
steps
{
script
{
jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
jenkinsLib.StartUbuntuTestNode()
}
}
}
stage('deploy')
{
parallel
{
stage('build SR docker image')
{
agent { label "master" }
steps
{
script
{
if ( CONCURRENCY == false )
{
//checkout scm
sh "docker build -t jenkins/scenario_runner:${COMMIT} ."
sh "docker tag jenkins/scenario_runner:${COMMIT} ${ECR_REPOSITORY}:${COMMIT}"
sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
sh "docker push ${ECR_REPOSITORY}"
sh "docker image rmi -f \"\$(docker images -q ${ECR_REPOSITORY}:${COMMIT})\""
}
else
{
println "SR docker image already built due concurrency"
}
}
}
}
stage('deploy CARLA')
{
stages
{
stage('install CARLA')
{
agent { label "secondary && ubuntu && gpu && sr" }
steps
{
println "using CARLA version ${CARLA_RELEASE}"
sh "wget -qO- ${CARLA_HOST}/${CARLA_RELEASE}.tar.gz | tar -xzv -C ."
}
}
}
}
}
}
stage('run test')
{
agent { label "secondary && ubuntu && gpu && sr" }
steps
{
sh 'DISPLAY= ./CarlaUE4.sh -opengl -nosound > CarlaUE4.log&'
sleep 10
script
{
sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
sh "docker pull ${ECR_REPOSITORY}:${COMMIT}"
sh "docker container run --rm --network host -e LANG=C.UTF-8 \"${ECR_REPOSITORY}:${COMMIT}\" -c \"python3 scenario_runner.py --scenario FollowLeadingVehicle_1 --debug --output --reloadWorld \""
deleteDir()
}
}
}
}
post
{
always
{
node('master')
{
script
{
jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
jenkinsLib.StopUbuntuTestNode()
echo 'test node stopped'
sh 'docker system prune --volumes -f'
}
deleteDir()
}
}
}
}
}
}