-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
99 lines (90 loc) · 3.72 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
pipeline {
agent {
docker {
image "maven:3.8.1-adoptopenjdk-11"
args '-v /root/.m2:/root/.m2'
}
}
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "https"
NEXUS_REPOSITORY = "maven-goudham"
NEXUS_URL = credentials('6a83eb53-ea59-45d0-9cd1-7c70b2720ba2')
NEXUS_CREDENTIAL_ID = credentials('e5582b32-3507-4e88-ab7c-d16d701c46e9')
CODECOV_TOKEN = credentials('e218fcc3-0253-4e98-ab9a-c0abfc97fb1b')
}
stages {
stage("Building") {
steps {
sh "mvn -B -DskipTests clean install"
}
}
stage("Testing") {
steps {
sh "mvn test"
}
}
stage("Deploying To Nexus") {
when {
branch 'release'
}
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";
}
}
}
}
}
post {
success {
echo "I'm Feeling Swag!"
echo "Generating Test Report..."
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')]
echo "Sending Report to CodeCov..."
sh '''#!/bin/bash
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN || echo "Codecov did not collect coverage reports"
'''
}
failure {
echo 'Not Very Swag :('
}
cleanup {
cleanWs()
}
}
}