From 946e12d32e24a3469bb0576292cd9e076185aa6f Mon Sep 17 00:00:00 2001 From: VSAzima Date: Fri, 23 Apr 2021 14:40:21 +0400 Subject: [PATCH] dzone way --- Jenkinsfile | 90 ++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5f30105a8..cd33944f7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,52 +31,52 @@ pipeline { } } } - stage('checkout') { - steps { - checkout scm - } -} -// stage('Publish') { -// def pom = readMavenPom file: 'pom.xml' -// nexusPublisher nexusInstanceId: 'your-nexus-instance-id', \ -// nexusRepositoryId: ${env.NEXUS_REPOSITORY}, \ -// packages: [[$class: 'MavenPackage', \ -// mavenAssetList: [[classifier: '', extension: '', filePath: "target/${pom.artifactId}-${pom.version}.${pom.packaging}"], \ -// [classifier: 'sources', extension: '', filePath: "target/${pom.artifactId}-${pom.version}-sources.${pom.packaging}"]], \ -// mavenCoordinate: [artifactId: "${pom.artifactId}", \ -// groupId: "${pom.groupId}", \ -// packaging: "${pom.packaging}", \ -// version: "${pom.version}-${env.BUILD_NUMBER}"]]] -// } - stage('push') { - steps { - nexusPublisher nexusInstanceId: 'maven-nexus-repo', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '.jar', filePath: '/target/']], mavenCoordinate: [artifactId: 'spring-petclinic', groupId: 'org.springframework.samples', packaging: 'pom', version: '2.4.2']]] - // 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: "${env.NEXUS_VERSION}", protocol: "${env.NEXUS_PROTOCOL}", nexusUrl: "${env.NEXUS_URL}", groupId: pom.groupId, version: pom.version, repository: "${env.NEXUS_REPOSITORY}", credentialsId: "${env.NEXUS_CREDENTIAL_ID}", artifacts: [ - // [artifactId: pom.artifactId, - // classifier: '', - // file: artifactPath, - // type: pom.packaging], - // [artifactId: pom.artifactId, - // classifier: '', - // file: "pom.xml", - // type: "pom"] - // ] - // ; - } + 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"; + } + } - // } else { - // error "*** File: ${artifactPath}, could not be found"; - // } } } } + }