Created
February 24, 2020 10:09
-
-
Save Tahooralisyed/8eb98110eab8c4f79b540e673ba958f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
//tool name: '', type: 'maven' | |
stage('Enviroment variable'){ | |
env.nexusVersion="nexus3" | |
env.nexusProtocol = "http" | |
env.nexusUrl = "13.233.237.222:8081" | |
env.nexusRepository = "auction-snapshot" | |
env.nexuscredentialsId = "nexus" | |
} | |
environment{ | |
nexusVersion = "nexus3" | |
// This can be http or https | |
NEXUS_PROTOCOL = "http" | |
// Where your Nexus is running | |
NEXUS_URL = "13.233.237.222:8081" | |
// Repository where we will upload the artifact | |
NEXUS_REPOSITORY = "auction-snapshot" | |
// Jenkins credential id to authenticate to Nexus OSS | |
NEXUS_CREDENTIAL_ID = "nexus" | |
} | |
//nexusArtifactUploader artifacts: [[artifactId: 'pom.artifactId', classifier: '', file: 'artifactPath', type: 'pom.packaging'], [artifactId: 'pom.artifactId', classifier: '', file: 'pom.xml', type: 'pom']], credentialsId: 'nexus', groupId: 'nexus', nexusUrl: '13.126.208.52:8081', nexusVersion: 'nexus3', protocol: 'http', repository: 'http://13.126.208.52:8081/repository/auction-snapshot/', version: ' 3.20.1-01' | |
stage('clone code') { | |
git 'https://github.com/danielalejandrohc/cargotracker.git' | |
} | |
stage('mvn build') { | |
sh "mvn package -DskipTests=true" | |
} | |
stage('publish to nexus') { | |
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: env.nexusVersion, | |
protocol: env.nexusProtocol, | |
nexusUrl: env.nexusUrl, | |
groupId: pom.groupId, | |
version: pom.version, | |
repository: env.nexusRepository, | |
env.nexuscredentialsId: 'nexus', | |
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"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment