Skip to content

Instantly share code, notes, and snippets.

@shaunthegeek
Created November 27, 2019 05:38
Show Gist options
  • Select an option

  • Save shaunthegeek/30288ca2252f9463b79c30306fedc649 to your computer and use it in GitHub Desktop.

Select an option

Save shaunthegeek/30288ca2252f9463b79c30306fedc649 to your computer and use it in GitHub Desktop.
Jenkins multiple Docker containers in the background, instead of sidecar
node {
checkout scm
sh 'docker network create bridge1';
sh(script:'docker run --net bridge1 --name mysql -d -e "MYSQL_ROOT_PASSWORD=my-secret-pw" -e "MYSQL_DATABASE=test" mysql:5.7', returnStdout: true)
sh(script:'docker run --net bridge1 --name redis -d redis:5', returnStdout: true)
def testImage = docker.build("test-image:${env.BUILD_ID}", "-f Dockerfile ./")
testImage.inside('--net bridge1 -e "DB_HOST=mysql" -e "REDIS_HOST=redis" -e "DB_DATABASE=test" -e "DB_USERNAME=root" -e "DB_PASSWORD=my-secret-pw"') {
stage('Prepare') {
echo 'preparing'
sh 'env'
sh 'apt-get update && apt-get install -y librsvg2-bin'
}
stage('Test') {
echo 'testing...'
sh 'ls'
}
}
}
@shaunthegeek
Copy link
Author

@KrzysztofMadejski you don't need to stop them, they will be stoped by Jenkins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment