From ddc7ef18a6c68a541492d98b243aa5625b7c93d2 Mon Sep 17 00:00:00 2001 From: Dominik Chilla Date: Mon, 17 Jun 2019 18:56:10 +0200 Subject: [PATCH] Jenkins docker.inside() --- Jenkinsfile | 8 ++-- Jenkinsfile.declarative | 40 ------------------ Jenkinsfile.declarative.multibranch | 65 ----------------------------- Jenkinsfile.scripted | 29 ------------- Jenkinsfile.scripted.multibranch | 31 -------------- 5 files changed, 3 insertions(+), 170 deletions(-) delete mode 100644 Jenkinsfile.declarative delete mode 100644 Jenkinsfile.declarative.multibranch delete mode 100644 Jenkinsfile.scripted delete mode 100644 Jenkinsfile.scripted.multibranch diff --git a/Jenkinsfile b/Jenkinsfile index d05e89f..28473ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +def dockerImageObj + pipeline { agent any @@ -7,10 +9,6 @@ pipeline { string defaultValue: 'sos-milter', name: 'imageName', trim: true } - environment { - dockerImageObj = '' - } - stages { stage('Build image') { steps { @@ -26,7 +24,7 @@ pipeline { stage('Test image') { steps { script { - dockerImageObj.inside { + dockerImageObj.inside("python3") { sh 'echo "INSIDE CONTAINER!"' sh '/usr/bin/env' sh '/bin/ps auxwwf' diff --git a/Jenkinsfile.declarative b/Jenkinsfile.declarative deleted file mode 100644 index 483e612..0000000 --- a/Jenkinsfile.declarative +++ /dev/null @@ -1,40 +0,0 @@ -def dockerImage = '' - -pipeline { - agent any - - stages { - stage('Build image') { - steps { - sh '/usr/bin/env' - script { - /* Multi-Branch Pipeline works with env.BRANCH_NAME*/ - dockerImage = docker.build("sos-milter:${env.BRANCH_NAME}","--pull --label BUILD_URL=${env.BUILD_URL} .") - } - } - } - stage('Test image') { - steps { - script { - dockerImage.inside { - sh '/usr/bin/env' - sh '/bin/ps auxwwf' - } - } - } - } - stage('Push image') { - steps { - script { - dockerImage.push() - } - } - } - stage('Cleanup') { - steps { - sh 'echo "TODO: cleanup!"' - } - } - } -} - diff --git a/Jenkinsfile.declarative.multibranch b/Jenkinsfile.declarative.multibranch deleted file mode 100644 index d05e89f..0000000 --- a/Jenkinsfile.declarative.multibranch +++ /dev/null @@ -1,65 +0,0 @@ -pipeline { - agent any - - parameters { - string defaultValue: 'https', name: 'dockerRegistryScheme', trim: true - string defaultValue: 'example.com', name: 'dockerRegistryRepo', trim: true - string defaultValue: 'sos-milter', name: 'imageName', trim: true - } - - environment { - dockerImageObj = '' - } - - stages { - stage('Build image') { - steps { - sh '/usr/bin/env' - script { - dockerImageObj = docker.build( - "${env.imageName}:${env.BRANCH_NAME}", - "--pull --label BUILD_URL=${env.BUILD_URL} ." - ) - } - } - } - stage('Test image') { - steps { - script { - dockerImageObj.inside { - sh 'echo "INSIDE CONTAINER!"' - sh '/usr/bin/env' - sh '/bin/ps auxwwf' - } - } - } - } - stage('Push image') { - steps { - script { - docker.withRegistry("${env.dockerRegistryScheme}://${env.dockerRegistryRepo}") { - dockerImageObj.push() - } - } - } - } - stage('Cleanup') { - steps { - echo "Cleanup" - /* The default is to reuse the local images for future builds. The reason - for this is quite simple! It´s much easier to prune local images from - disk than pushed images from the (cheap) docker registry! */ - /* Uncomment the following directives if you want your build host to stay - clean from local docker images after successfull push. But, there is a - caveat if you do so! Each build job produces at least one new image layer - which gets pushed to the registry. This could blow up your registry after - a couple of time! For garbage collection check this out: - https://docs.docker.com/registry/garbage-collection/ */ - /* echo "Remove local docker images after successfull push to registry..." */ - /* sh '/usr/bin/docker rmi -f "${imageName}:${BRANCH_NAME}"' */ - /* sh '/usr/bin/docker rmi -f "${dockerRegistryRepo}/${imageName}:${BRANCH_NAME}"' */ - } - } - } -} - diff --git a/Jenkinsfile.scripted b/Jenkinsfile.scripted deleted file mode 100644 index e71a5d3..0000000 --- a/Jenkinsfile.scripted +++ /dev/null @@ -1,29 +0,0 @@ -node { - def docker_image - - stage('Clone repository') { - sh '/usr/bin/env' - /* Let's make sure we have the repository cloned to our workspace */ - checkout scm - } - - stage('Build image') { - /* This builds the actual image; synonymous to - * docker build on the command line */ - docker_image = docker.build("jenkins/sos-milter") - } - - stage('Test image') { - /* Ideally, we would run a test framework against our image. - * For this example, we're using a Volkswagen-type docker_imageroach ;-) */ - docker_image.inside { - sh 'echo "Tests passed"' - } - } - - stage('Push image') { - docker.withRegistry('https://dockreg-fra.zwackl.de') { - docker_image.push() - } - } -} diff --git a/Jenkinsfile.scripted.multibranch b/Jenkinsfile.scripted.multibranch deleted file mode 100644 index f8281dd..0000000 --- a/Jenkinsfile.scripted.multibranch +++ /dev/null @@ -1,31 +0,0 @@ -node { - def app - - stage('Clone repository') { - sh '/usr/bin/env' - checkout scm - } - - stage('Build image') { - sh '/usr/bin/env' - /* Multi-Branch Pipeline works with env.BRANCH_NAME*/ - app = docker.build("sos-milter:${env.BRANCH_NAME}","--pull --label BUILD_URL=${env.BUILD_URL} .") - } - - stage('Test image') { - app.inside { - sh '/usr/bin/env' - sh '/bin/ps auxwwf' - } - } - - stage('Push image') { - docker.withRegistry('https://dockreg-fra.zwackl.de') { - app.push() - } - } - - stage('Cleanup') { - sh 'echo "TODO: cleanup!"' - } -}