mirror of
https://github.com/chillout2k/sos-milter.git
synced 2025-12-11 01:30:19 +00:00
Jenkins docker.inside()
This commit is contained in:
parent
f497d842f2
commit
ddc7ef18a6
8
Jenkinsfile
vendored
8
Jenkinsfile
vendored
@ -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'
|
||||
|
||||
@ -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!"'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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}"' */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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!"'
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user