Commit 2293aa99 authored by Fernando Vazquez's avatar Fernando Vazquez

Added nexus stage and env variables

parent 46ac176a
...@@ -4,6 +4,14 @@ pipeline { ...@@ -4,6 +4,14 @@ pipeline {
maven 'maven' maven 'maven'
} }
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "34.69.185.118:8081"
NEXUS_REPOSITORY = "maven-nexus-jenkins-repo"
NEXUS_CREDENTIAL_ID = "nexus-credentials"
}
stages { stages {
stage('Git Checkout') { stage('Git Checkout') {
steps{ steps{
...@@ -18,6 +26,16 @@ pipeline { ...@@ -18,6 +26,16 @@ pipeline {
sh 'mvn -Dmaven.test.failure.ignore=false install' sh 'mvn -Dmaven.test.failure.ignore=false install'
} }
} }
stage('Test'){
steps{
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('SonarQube Analysis') { stage('SonarQube Analysis') {
steps{ steps{
withSonarQubeEnv('Sonarqube') { withSonarQubeEnv('Sonarqube') {
...@@ -32,5 +50,51 @@ pipeline { ...@@ -32,5 +50,51 @@ pipeline {
} }
} }
} }
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";
}
}
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment