123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #!/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()
- }
- }
- }
- }
- }
- }
|