-
Notifications
You must be signed in to change notification settings - Fork 150
/
Jenkinsfile-sonarscanner-updated
80 lines (76 loc) · 3.25 KB
/
Jenkinsfile-sonarscanner-updated
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
pipeline{
agent any
tools{
maven 'maven-3.9.0'
}
stages{
stage('git checkout using ssh'){
steps{
git branch: 'master', credentialsId: 'jenkins-ssh-private-key', url: '[email protected]:cloudtechmasters/springboot-maven-course-micro-svc.git'
}
}
stage('build maven project'){
steps{
sh 'mvn clean package'
}
}
stage("Deploy to Sonar") {
steps{
script{
withSonarQubeEnv(installationName: 'sonarqube-9.9.0.65466', credentialsId: 'jenkins-sonar-token') {
sh "${ tool ("sonar-scanner-4.8.0.2856")}/sonar-scanner"
}
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
stage("Publish to Nexus Repository Manager") {
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: [
[artifactId: pom.artifactId,
classifier: '',
file: artifactPath,
type: pom.packaging],
[artifactId: pom.artifactId,
classifier: '',
file: "pom.xml",
type: "pom"]
]
);
} else {
error "*** File: ${artifactPath}, could not be found";
}
}
}
}
}
post {
success {
mail bcc: '', body: 'nexus artifact uploaded successfully', cc: '', from: '[email protected]', replyTo: '', subject: 'The Pipeline success', to: '[email protected]'
}
failure {
mail bcc: '', body: 'nexus artifact uploaded failed', cc: '', from: '[email protected]', replyTo: '', subject: 'The Pipeline failed', to: '[email protected]'
}
}
}