forked from calamza/holamundo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.groovy
105 lines (95 loc) · 3.6 KB
/
build.groovy
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
100
101
102
103
104
105
pipeline{
agent {
label 'maven'
}
/*
tools {
maven 'maven 3.6'
jdk 'java'
}
*/
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-3' is defined in the docker-compose file
NEXUS_URL = "192.168.42.131:8081"
// Repository where we will upload the artifact
NEXUS_REPOSITORY = "maven-releases"
// Jenkins credential id to authenticate to Nexus OSS
NEXUS_CREDENTIAL_ID = "nexus"
// Workfolder
//WORKFOLDER = "/usr/jenkins/node_agent/workspace"
}
stages{
stage('Checkout'){
steps{
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'github', url: '[email protected]:calamza/holamundo.git']]])
}
}
stage('Build artifact'){
agent {
label 'maven'
}
steps{
sh '''
#mvn clean install
/opt/apache-maven-3.6.3/bin/mvn package
'''
}
}
stage('Upload to nexus'){
agent {
label 'maven'
}
steps{
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: 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";
}
}
}
} //fin stage upload
stage("Post") {
agent {
label 'docker'
}
steps {
sh '''
pwd
echo "Clean up workfolder"
rm -Rf *
'''
}
} //fin stage post
}
}