From faa7341c538b3a95fed79b603ce79d29331b5cd6 Mon Sep 17 00:00:00 2001 From: agreiner Date: Sat, 7 Aug 2021 01:21:41 +0200 Subject: [PATCH] Added nexus push --- Jenkinsfile | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 17a1b83..0e28968 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,18 @@ pipeline { tools { maven 'Maven' jdk 'Java JDK' + } + environment { + // This can be nexus3 or nexus2 + NEXUS_VERSION = "nexus3" + // This can be http or https + NEXUS_PROTOCOL = "http" + // Where your Nexus is running + NEXUS_URL = "https://Nexus.greinet.com" + // Repository where we will upload the artifact + NEXUS_REPOSITORY = "maven-greinet" + // Jenkins credential id to authenticate to Nexus OSS + NEXUS_CREDENTIAL_ID = " nexus_jenkins" } stages { stage ('Initialize') { @@ -19,5 +31,51 @@ pipeline { sh 'mvn -Dmaven.test.failure.ignore=true install' } } + stage("publish to nexus") { + steps { + script { + // Read POM xml file using 'readMavenPom' step , this step 'readMavenPom' is included in: https://plugins.jenkins.io/pipeline-utility-steps + pom = readMavenPom file: "pom.xml"; + // Find built artifact under target folder + filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); + // Print some info from the artifact found + echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" + // Extract the path from the File found + artifactPath = filesByGlob[0].path; + // Assign to a boolean response verifying If the artifact name exists + 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: [ + // Artifact generated such as .jar, .ear and .war files. + [artifactId: pom.artifactId, + classifier: '', + file: artifactPath, + type: pom.packaging], + + // Lets upload the pom.xml file for additional information for Transitive dependencies + [artifactId: pom.artifactId, + classifier: '', + file: "pom.xml", + type: "pom"] + ] + ); + + } else { + error "*** File: ${artifactPath}, could not be found"; + } + } + } + } } } \ No newline at end of file