Jenkinsfile 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env groovy
  2. String CARLA_HOST
  3. String CARLA_RELEASE
  4. String TEST_HOST
  5. String COMMIT
  6. String ECR_REPOSITORY = "456841689987.dkr.ecr.eu-west-3.amazonaws.com/scenario_runner"
  7. boolean CARLA_RUNNING = false
  8. boolean CONCURRENCY = true
  9. // V3 - include detection of concurrent builds
  10. pipeline
  11. {
  12. agent none
  13. options
  14. {
  15. buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3'))
  16. skipDefaultCheckout()
  17. }
  18. stages
  19. {
  20. stage('setup')
  21. {
  22. agent { label "master" }
  23. steps
  24. {
  25. checkout scm
  26. script
  27. {
  28. jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
  29. TEST_HOST = jenkinsLib.getUbuntuTestNodeHost()
  30. CARLA_HOST= sh(
  31. script: "cat ./CARLA_VER | grep HOST | sed 's/HOST\\s*=\\s*//g'",
  32. returnStdout: true).trim()
  33. CARLA_RELEASE = sh(
  34. script: "cat ./CARLA_VER | grep RELEASE | sed 's/RELEASE\\s*=\\s*//g'",
  35. returnStdout: true).trim()
  36. COMMIT = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
  37. }
  38. println "using CARLA version ${CARLA_RELEASE} from ${TEST_HOST}"
  39. }
  40. }
  41. stage('get concurrency status')
  42. {
  43. options
  44. {
  45. lock resource: 'ubuntu_gpu', skipIfLocked: true
  46. }
  47. agent { label "master" }
  48. steps
  49. {
  50. script
  51. {
  52. CONCURRENCY = false
  53. println "no concurrent builds detected."
  54. }
  55. }
  56. }
  57. stage('act on concurrency')
  58. {
  59. agent { label "master" }
  60. steps
  61. {
  62. script
  63. {
  64. if ( CONCURRENCY == true )
  65. {
  66. println "concurrent builds detected, prebuilding SR image."
  67. stage('prebuild SR docker image')
  68. {
  69. //checkout scm
  70. sh "docker build -t jenkins/scenario_runner:${COMMIT} ."
  71. sh "docker tag jenkins/scenario_runner:${COMMIT} ${ECR_REPOSITORY}:${COMMIT}"
  72. sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
  73. sh "docker push ${ECR_REPOSITORY}"
  74. sh "docker image rmi -f \"\$(docker images -q ${ECR_REPOSITORY}:${COMMIT})\""
  75. }
  76. }
  77. }
  78. }
  79. }
  80. stage('lock ubuntu_gpu instance')
  81. {
  82. options
  83. {
  84. lock resource: "ubuntu_gpu"
  85. }
  86. stages
  87. {
  88. stage('start server')
  89. {
  90. agent { label "master" }
  91. steps
  92. {
  93. script
  94. {
  95. jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
  96. jenkinsLib.StartUbuntuTestNode()
  97. }
  98. }
  99. }
  100. stage('deploy')
  101. {
  102. parallel
  103. {
  104. stage('build SR docker image')
  105. {
  106. agent { label "master" }
  107. steps
  108. {
  109. script
  110. {
  111. if ( CONCURRENCY == false )
  112. {
  113. //checkout scm
  114. sh "docker build -t jenkins/scenario_runner:${COMMIT} ."
  115. sh "docker tag jenkins/scenario_runner:${COMMIT} ${ECR_REPOSITORY}:${COMMIT}"
  116. sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
  117. sh "docker push ${ECR_REPOSITORY}"
  118. sh "docker image rmi -f \"\$(docker images -q ${ECR_REPOSITORY}:${COMMIT})\""
  119. }
  120. else
  121. {
  122. println "SR docker image already built due concurrency"
  123. }
  124. }
  125. }
  126. }
  127. stage('deploy CARLA')
  128. {
  129. stages
  130. {
  131. stage('install CARLA')
  132. {
  133. agent { label "secondary && ubuntu && gpu && sr" }
  134. steps
  135. {
  136. println "using CARLA version ${CARLA_RELEASE}"
  137. sh "wget -qO- ${CARLA_HOST}/${CARLA_RELEASE}.tar.gz | tar -xzv -C ."
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. stage('run test')
  145. {
  146. agent { label "secondary && ubuntu && gpu && sr" }
  147. steps
  148. {
  149. sh 'DISPLAY= ./CarlaUE4.sh -opengl -nosound > CarlaUE4.log&'
  150. sleep 10
  151. script
  152. {
  153. sh '$(aws ecr get-login | sed \'s/ -e none//g\' )'
  154. sh "docker pull ${ECR_REPOSITORY}:${COMMIT}"
  155. 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 \""
  156. deleteDir()
  157. }
  158. }
  159. }
  160. }
  161. post
  162. {
  163. always
  164. {
  165. node('master')
  166. {
  167. script
  168. {
  169. jenkinsLib = load("/home/jenkins/scenario_runner.groovy")
  170. jenkinsLib.StopUbuntuTestNode()
  171. echo 'test node stopped'
  172. sh 'docker system prune --volumes -f'
  173. }
  174. deleteDir()
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }