forked from MithunTechnologiesDevOps/maven-web-application
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
88 lines (62 loc) · 2.34 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
node{
def mavenTool = tool 'maven3.9.2'
stage('checkout code'){
git credentialsId: 'Jenkins_Github_crd', url: 'https://github.com/lokeshsgithub/maven-web-application.git'
}
stage('UNIT testing'){
sh "${mavenTool}/bin/mvn test"
}
stage('INTEGRATION testing'){
sh "${mavenTool}/bin/mvn verify -DskipUnitTests"
}
stage('Maven Build'){
sh "${mavenTool}/bin/mvn clean install"
}
stage('static code analysis'){
withSonarQubeEnv(credentialsId: 'sonar_auth') {
sh "${mavenTool}/bin/mvn clean package sonar:sonar"
}
}
stage('Quality Gate'){
waitForQualityGate abortPipeline: false, credentialsId: 'sonar_auth'
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
stage('nexus artifact uploader'){
def readPomVersion = readMavenPom file: 'pom.xml'
def nexusRepo = readPomVersion.version.endsWith("SNAPSHOT") ? "mavenwebapp-Snapshot" : "mavenwebapp-release"
nexusArtifactUploader artifacts:
[
[
artifactId: 'maven-web-application',
classifier: '', file: 'target/maven-web-application.war',
type: 'war'
]
],
credentialsId: 'Nexus_crd',
groupId: 'com.mt',
nexusUrl: '13.127.59.129:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: nexusRepo,
version: "${readPomVersion.version}"
}
stage('Deploy the application in tomcat server'){
sshagent(['Tomcat_pwd']) {
sh "scp -o StrictHostKeyChecking=no */*.war [email protected]:/opt/apache-tomcat-9.0.75/webapps"
}
}
stage ('Send Email') {
echo "Mail Stage";
mail to: "[email protected]",
cc: '[email protected]', charset: 'UTF-8',
from: '[email protected]', mimeType: 'text/html', replyTo: '',
bcc: '',
subject: "CI: Project name -> ${env.JOB_NAME}",
body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}";
}
}