From 1aea7bf218e5a85974daf459384a66f2652f90dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Mattm=C3=BCller?= Date: Mon, 19 Jun 2023 18:33:08 +0200 Subject: [PATCH] jobs: added artifact deployment to nexus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc Mattmüller --- jobs/Jenkinsfile_Build | 18 +++++++++++++++--- jobs/Jenkinsfile_Common | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/jobs/Jenkinsfile_Build b/jobs/Jenkinsfile_Build index f13b1c6..c407cff 100644 --- a/jobs/Jenkinsfile_Build +++ b/jobs/Jenkinsfile_Build @@ -80,9 +80,9 @@ pipeline { script { dir("${env.YOCTO_REPO_DIR}") { common.buildTheYoctoPackage() - def artifactName = "NWL-${machine}.zip" + env.ARTIFACT_NAME = "NWL-${machine}.zip" common.collectingPackageArtifacts("${env.MACHINE}") - common.packAndArchiveArtifacts("${env.MACHINE}", artifactName) + common.packAndArchiveArtifacts("${env.MACHINE}", "${env.ARTIFACT_NAME}") } println "TODO: sync sstate-cache to the server" } @@ -93,7 +93,7 @@ pipeline { when { expression { return common.isCurrentJobSuccess() } } steps { script { - println "TODO: Deploy artifacts" + deployToArtifactory(common) } } } @@ -162,3 +162,15 @@ def setupEnvironment(commonHelpers) { commonHelpers.setupBuildEnvironment(machine, nwlBranch, nwlRepoDir, params.DEBUGGING) commonHelpers.printEnvironmentParameters() } + + +//--------------------------------------------------------------------------------------------------------------------- +def deployToArtifactory(commonHelpers) { + def artifactFilepath = "${env.DEPLOY_CONTENT_DIR}/${env.ARTIFACT_NAME}" + def nexusGroupId = "nwl.${env.CI_IMAGE}" + def nexusArtifactId = "${env.MACHINE}" + def nexusVersion = "latest" + + println "deploying ${artifactFilepath} as ${nexusGroupId}.${nexusArtifactId} to Nexus..." + commonHelpers.deployArtifactToNexusArtifactory(artifactFilepath, "zip", nexusGroupId, nexusArtifactId, nexusVersion) +} diff --git a/jobs/Jenkinsfile_Common b/jobs/Jenkinsfile_Common index f08fac5..195c088 100644 --- a/jobs/Jenkinsfile_Common +++ b/jobs/Jenkinsfile_Common @@ -24,6 +24,15 @@ env.YOCTO_RELEASE = 'kirkstone' env.CI_IMAGE = "nwl-image-testable" +// Artifactory +//---------------------------- +env.NEXUS_URL = "artifactory.gad.local:443" +env.NEXUS_VERSION = "nexus3" +env.NEXUS_PROTOCOL = "https" +env.NEXUS_REPOSITORY = "maven-releases" +env.NEXUS_ARTIFACT_COPIER_URL = "${env.NEXUS_PROTOCOL}://${env.NEXUS_URL}/repository/${env.NEXUS_REPOSITORY}" + + // Methods declared in external code are accessible // directly from other code in the external file // indirectly via the object created by the load operation @@ -320,6 +329,27 @@ def packAndArchiveArtifacts(machine, pkgArchiveName) { } +//----------------------------------------------------------------------------- +// deploy an artifact to the Nexus Artifactory +def deployArtifactToNexusArtifactory(artifactPathname, artifactType, groupId, artifactId, version) { + nexusArtifactUploader( + nexusVersion: "${env.NEXUS_VERSION}", + protocol: "${env.NEXUS_PROTOCOL}", + nexusUrl: "${env.NEXUS_URL}", + groupId: "${groupId}", + version: "${version}", + repository: "${env.NEXUS_REPOSITORY}", + credentialsId: "nexus_uploader_credentials", + artifacts: [ + [artifactId: "${artifactId}", + classifier: "", + file: "${artifactPathname}", + type: "${artifactType}"] + ] + ); +} + + // !!Important Boilerplate!! // The external code must return it's contents as an object return this;