Here is an example of a pipeline script that builds a Docker container, then runs the tests inside of it. The entrypoint is assumed to be either manage.py
or invoke
/fabric
with a runtests
command available.
#!/usr/bin/groovy
node {
stage 'Checkout'
checkout scm
sh 'git submodule update --init --recursive'
imageName = 'mycontainer:build'
remotes = [
'dockerhub-account',
]
stage 'Build'
def djangoImage = docker.build imageName
stage 'Run Tests'
djangoImage.run('', 'runtests')
stage 'Push'
for (int i = 0; i < remotes.size(); i++) {
sh "docker tag ${imageName} ${remotes[i]}/${imageName}"
sh "docker push ${remotes[i]}/${imageName}"
}
}