diff --git a/vars/continuousIntegrationPipeline.groovy b/vars/continuousIntegrationPipeline.groovy index 84a0af3..021dd74 100644 --- a/vars/continuousIntegrationPipeline.groovy +++ b/vars/continuousIntegrationPipeline.groovy @@ -115,6 +115,23 @@ def call(Map pipelineParams = [:]) { } } + stage ("Deploy on Nexus Repository") { + // Call uploadPackages only if we are on the default branch, + // if we have DEB packages to upload and if the user has set the pushArtifacts parameter to true + if (env.BRANCH_IS_PRIMARY && pipelineParams.pushArtifacts) { + echo "Uploading DEB packages..." + + def distribPom = readMavenPom file: 'workdir/distrib/pom.xml' + + def repoDistribution = distribPom.properties['kura.repo.distribution'] + def repoModule = distribPom.properties['kura.repo.module'] + + uploadPackages(repoDistribution, repoModule) + } else { + echo "Skipping DEB packages upload." + Utils.markStageSkippedForConditional(STAGE_NAME) + } + } stage ("Archive artifacts") { dir("workdir") { diff --git a/vars/uploadPackages.groovy b/vars/uploadPackages.groovy new file mode 100644 index 0000000..ec92f3f --- /dev/null +++ b/vars/uploadPackages.groovy @@ -0,0 +1,50 @@ +def call(String repoDistribution, String repoModule, Boolean setupPromotion = false) { + stage ("Upload packages parameters check") { + echo "Distribution: ${repoDistribution}" + echo "Module: ${repoModule}" + + // Check "distribution" parameter is set and valid + assert repoDistribution instanceof String + assert repoDistribution ==~ /kura-\d+/ + + // Check "module" parameter is set and valid + def valid_modules = [ + "base" + ] + + assert repoModule instanceof String + assert valid_modules.contains(repoModule) + } + + stage("Upload .deb packages to Nexus") { + def debFiles = findFiles(glob: 'workdir/**/*.deb') + + if (debFiles.size() == 0) { + error("No .deb files found to upload") + } + + debFiles.each { + withCredentials([usernameColonPassword(credentialsId: 'repo.eclipse.org-bot-account', variable: 'USERPASS')]) { + def status = sh( + script: """ + curl -u \"\$USERPASS\" \ + -w '%{http_code}' \ + -H \"Content-Type: multipart/form-data\" \ + --data-binary \"@./${it}\" \ + \"https://repo3.eclipse.org/repository/kura-apt-dev/\" \ + -o /dev/null + """, + returnStdout: true + ).trim() + + if (status != "201") { + error("Returned status code = $status") + } + } + } + + if (setupPromotion) { + // TODO + } + } +}