From 02c9380a8c1e8ad42580824a6bc817ecbd5b3c86 Mon Sep 17 00:00:00 2001 From: VSAzima Date: Thu, 22 Apr 2021 18:44:31 +0400 Subject: [PATCH] nexus stage added --- Jenkinsfile | 59 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 267f8205c..8279b68e0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,12 @@ pipeline { agent any + environment { + NEXUS_VERSION = "nexus3" + NEXUS_PROTOCOL = "http" + NEXUS_URL = "172.19.0.3:8081" + NEXUS_REPOSITORY = "maven-nexus-repo" + NEXUS_CREDENTIAL_ID = "nexus-user-credentials" + } stages { stage('pull') { steps { @@ -12,19 +19,45 @@ pipeline { steps { script { docker.image('maven:3.8.1-jdk-8').inside { - // /var/jenkins_home/workspace/MeFirstPipelineJob sh 'mvn -B clean package' } } -} -} - // } - // // stage('push') { - // // steps { - // // echo 'Pushing ...' - // // - // // } - // // } - // } -} -} + } + } + stage('push') { + steps { + script { + pom = readMavenPom file: "pom.xml"; + filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); + echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" + artifactPath = filesByGlob[0].path; + artifactExists = fileExists artifactPath; + if(artifactExists) { + echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}"; + nexusArtifactUploader( + nexusVersion: NEXUS_VERSION, + protocol: NEXUS_PROTOCOL, + nexusUrl: NEXUS_URL, + groupId: pom.groupId, + version: pom.version, + repository: NEXUS_REPOSITORY, + credentialsId: NEXUS_CREDENTIAL_ID, + artifacts: [ + [artifactId: pom.artifactId, + classifier: '', + file: artifactPath, + type: pom.packaging], + [artifactId: pom.artifactId, + classifier: '', + file: "pom.xml", + type: "pom"] + ] + ); + } else { + error "*** File: ${artifactPath}, could not be found"; + } + } + } + } + } + }