debian/Jenkinsfile

79 lines
3.4 KiB
Text
Raw Permalink Normal View History

2020-10-28 16:30:37 +00:00
version = "10"
project = "debian"
repo = "zknt"
registry = "reg.zknt.org"
registry_credentials = "6ff44976-23cd-4cc2-902c-de8c340e65e5"
2020-05-28 11:02:04 +00:00
timeStamp = Calendar.getInstance().getTime().format('YYYY-MM-dd',TimeZone.getTimeZone('UTC'))
pipeline {
agent any
2020-10-28 16:30:37 +00:00
stages {
stage('Build image') {
steps {
withDockerRegistry([ credentialsId: registry_credentials, url: "https://"+registry ]) {
script {
def customImage = docker.build(registry+'/'+repo+'/'+project, "--pull --build-arg VERSION=$version --build-arg DATE=$timeStamp .")
customImage.push(version)
customImage.push("buster")
customImage.push("stable")
def io_registry_credentials = "3deeee3d-6fce-4430-98dd-9b4db56f43f7"
withDockerRegistry([ credentialsId: io_registry_credentials ]) {
def io_registry_image = repo + '/' + project + ':' + version
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + io_registry_image
sh "docker push " + io_registry_image
2020-10-28 23:35:30 +00:00
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + io_registry_image.split(/\:/)[0] + ":buster"
sh "docker push " + io_registry_image.split(/\:/)[0] + ":buster"
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + io_registry_image.split(/\:/)[0] + ":stable"
sh "docker push " + io_registry_image.split(/\:/)[0] + ":stable"
2020-10-28 16:30:37 +00:00
}
2020-05-28 11:02:04 +00:00
2020-10-28 16:30:37 +00:00
def quay_credentials= "18fb6f7e-c6bc-4d06-9bf9-08c2af6bfc1a"
withDockerRegistry([ credentialsId: quay_credentials, url: "https://quay.io" ]) {
def quay_image = 'quay.io/' + repo + '/' + project + ':' + version
2020-10-28 23:35:30 +00:00
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + quay_image
2020-10-28 16:30:37 +00:00
sh "docker push " + quay_image
2020-10-28 23:35:30 +00:00
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + quay_image.split(/\:/)[0] + ":buster"
sh "docker push " + quay_image.split(/\:/)[0] + ":buster"
sh "docker image tag " + registry+'/'+repo+'/'+project+':'+version + ' ' + quay_image.split(/\:/)[0] + ":stable"
sh "docker push " + quay_image.split(/\:/)[0] + ":stable"
2020-10-28 16:30:37 +00:00
}
2020-05-28 11:02:04 +00:00
}
}
}
}
}
2020-10-28 16:30:37 +00:00
2020-05-28 11:02:04 +00:00
post {
2020-11-04 00:55:43 +00:00
always {
sh """docker container prune -f"""
2020-10-28 23:35:30 +00:00
sh """docker image prune -f"""
2020-10-23 17:53:15 +00:00
sh """docker rmi -f \$(docker images -q $registry/$repo/$project:$version)"""
2020-10-29 14:56:58 +00:00
sh """for image in \$(grep FROM Dockerfile | cut -d ' ' -f 2 | grep -vi -e SCRATCH -e bootstrapped | uniq); do docker rmi -f \$(docker images -q \${image}); done"""
2020-10-28 16:30:37 +00:00
emailext body: 'build finished', subject: '[jenkins] docker '+project+'('+version+'): ' + currentBuild.result, to: 'cg@zknt.org', from: 'sysadm@zknt.org', attachLog: true
2020-05-28 11:02:04 +00:00
}
}
options {
buildDiscarder(BuildHistoryManager([
[
conditions: [
BuildResult(matchFailure: true)
],
matchAtMost: 4,
continueAfterMatch: false
],
[
conditions: [
BuildResult(matchSuccess: true)
],
2020-10-28 16:30:37 +00:00
matchAtMost: 4,
2020-05-28 11:02:04 +00:00
continueAfterMatch: false
],
[
conditions: [
BuildResult(matchSuccess: true, matchFailure: true)
],
actions: [DeleteBuild()]
]
]))
}
2020-10-28 16:30:37 +00:00
}