From 9a3028afaac72486ee053d11acf16b55f2f77703 Mon Sep 17 00:00:00 2001 From: Marc Mattmueller Date: Wed, 5 May 2021 12:03:09 +0200 Subject: [PATCH] jenkins: sync binary storage before and after build Signed-off-by: Marc Mattmueller --- Jenkinsfile | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 221d632..8ca1aea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -65,7 +65,6 @@ pipeline { ----------------------------------\n" changeDistroVersion("${version}") syncSources("${env.BINARY_STORAGE_URL}", "${env.SHARED_BUILD}/downloads") - error("STOPPING because I want it so... :-D") } writeFile file: 'VERSION', text: "${env.PACKAGE_NAME}: ${env.BUILD_VERSION}" } @@ -104,6 +103,13 @@ pipeline { } sh "rm -rf ${WORKSPACE}/tmp" } + post { + always { + script { + syncSources("${env.SHARED_BUILD}/downloads", "${env.BINARY_STORAGE_URL}") + } + } + } } } // stages } @@ -166,25 +172,26 @@ def cleanupDistroVersion() { } def syncSources(src, dst) { - def url = (src.contains("http")) ? src : dst - def repoUrl = url.split("//")[1] - String[] repoParts = "${repoUrl}".split("/") + def hasSrcUrl = (src.contains("http")) + def syncCmd = "rsync -avz -e \"ssh\"" + def from = src + def to = dst + + // convert the URL into ssh syntax: + def url = (hasSrcUrl) ? src : dst + String[] repoParts = url.split("//")[1].split("/") repoParts[0] = "jenkins@" + repoParts[0] + ":/repo/repo" sshSrc = repoParts.join("/") - println "sshSrc=${sshSrc}" - def syncCmd = "rsync -avz -e \"ssh\"" - - // http://nmrepo.netmodule.intranet/src/yocto-downloads/ - - // synchronizing build job - if(src.contains("http")) { + if(hasSrcUrl) { println "getting data from server..." -// sh(script: "rsync -avz -e \"ssh\" ${sshSrc} ${dst}") - return + from = sshSrc } - // synchronizing storage - println "putting data to server..." + else { + println "putting data to server..." + to = sshSrc + } + sh(script: "${syncCmd} ${from}/ ${to}") }