Update Jenkinsfile

- Rewrite as declarative
- Add credentials
- Gate images pushes to master branch only

Signed-off-by: Dave Tucker <dt@docker.com>
This commit is contained in:
Dave Tucker 2018-08-16 23:27:20 +01:00
parent b832e37864
commit 0355778d6e

55
Jenkinsfile vendored
View File

@ -1,31 +1,54 @@
pipeline {
agent {
node {
def resultImage
def voteImage
def workerImage
docker.withRegistry("https://index.docker.io/v1/", "dockersamples" ) {
stage('Clone repo') {
checkout scm
label 'ubuntu-1604-aufs-stable'
}
}
stages {
stage('Build result') {
resultImage = docker.build("dockersamples/result", "./result")
steps {
sh 'docker build -t dockersamples/result ./result'
}
}
stage('Build vote') {
voteImage = docker.build("dockersamples/vote", "./vote")
steps {
sh 'docker build -t dockersamples/vote ./vote'
}
}
stage('Build worker') {
steps {
sh 'docker build -t dockersamples/worker ./worker'
}
stage('Build worker dotnet') {
workerImage = docker.build("dockersamples/worker", "./worker")
}
stage('Push result image') {
resultImage.push("${env.BUILD_NUMBER}")
resultImage.push()
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: 'dockerbuildbot-index.docker.io', url:'') {
sh 'docker push dockersamples/result'
}
}
}
stage('Push vote image') {
voteImage.push("${env.BUILD_NUMBER}")
voteImage.push()
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: 'dockerbuildbot-index.docker.io', url:'') {
sh 'docker push dockersamples/vote'
}
}
}
stage('Push worker image') {
workerImage.push("${env.BUILD_NUMBER}")
workerImage.push()
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: 'dockerbuildbot-index.docker.io', url:'') {
sh 'docker push dockersamples/worker'
}
}
}
}
}