From 0d293e4fcff674075900b34c79e2f11cae5c34e9 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 23 Oct 2020 19:49:27 +0200 Subject: [PATCH] manage artifacts --- Jenkinsfile | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3215f57..b557eab 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,7 @@ pipeline { withDockerRegistry([ credentialsId: registry_credentials, url: "https://"+registry ]) { echo 'Starting to build docker image' script { - def customImage = docker.build(registry+'/'+repo+'/'+project, "--build-arg VERSION=$version --build-arg DATE=$timeStamp .") + def customImage = docker.build(registry+'/'+repo+'/'+project, "--pull --build-arg VERSION=$version --build-arg DATE=$timeStamp .") customImage.push(version) customImage.push(version.split(/\./)[0,1].join('.')) customImage.push(version.split(/\./)[0]) @@ -43,8 +43,36 @@ pipeline { } post { + success { + sh """docker rmi -f \$(docker images -q $registry/$repo/$project:$version)""" + sh """for image in \$(grep FROM Dockerfile | cut -d ' ' -f 2); do docker rmi -f \$(docker images -q \${image}); done""" + } always { emailext body: 'build finished', subject: '[jenkins] docker '+project+': ' + currentBuild.result, to: 'cg@zknt.org', from: 'sysadm@zknt.org', attachLog: true } } + options { + buildDiscarder(BuildHistoryManager([ + [ + conditions: [ + BuildResult(matchFailure: true) + ], + matchAtMost: 4, + continueAfterMatch: false + ], + [ + conditions: [ + BuildResult(matchSuccess: true) + ], + matchAtMost: 4, + continueAfterMatch: false + ], + [ + conditions: [ + BuildResult(matchSuccess: true, matchFailure: true) + ], + actions: [DeleteBuild()] + ] + ])) + } }