-
Notifications
You must be signed in to change notification settings - Fork 12.1k
/
JenkinsfileJan2024
93 lines (77 loc) · 1.92 KB
/
JenkinsfileJan2024
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
pipeline{
agent any
tools{
maven 'maven3.9.6'
}
echo "The Job name is: ${env.JOB_NAME}"
echo "The Nod ename is: ${env.NODE_NAME}"
echo "The Build Number is: ${env.BUILD_NUMBER}"
echo "The Jenkins Home directory is: ${JENKINS_HOME}"
//Checkout code
stages{
stage('CheckOuteCode'){
steps{
sendSlackNotifications("STARTED")
git branch: 'development', credentialsId: 'f4d44680-6f7c-4889-b836-5ce7015057f8', url: 'https://github.com/MithunTechnologiesDevOps/maven-web-application.git'
}
}
//Build
stage('Build'){
steps{
sh "mvn clean package"
}
}
/*
//Execute SonarQube Report
stage('ExecuteSonarQubeReport'){
steps{
sh "mvn clean sonar:sonar"
}
}
// Upload Artifcats into Nexus
stage('UploadArtifcatsIntoNexus'){
steps{
sh "mvn clean deploy"
}
}
//Deploy App into Tomcat Server
stage('DeployAppIntoTomcat'){
steps{
sshagent(['ea56a0ef-94e7-43c1-99e3-d7e0947043a3']) {
sh "scp -o StrictHostKeyChecking=no target/maven-web-application.war ec2-user@172.31.1.56:/opt/apache-tomcat-9.0.86/webapps/"
}
}
}
*/
}//stages closing
post {
success {
sendSlackNotifications(currentBuild.result)
}
failure {
sendSlackNotifications(currentBuild.result)
}
}
}//pipeline closing
def sendSlackNotifications(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
// Override default values based on build status
if (buildStatus == 'STARTED') {
colorName = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESS') {
colorName = 'GREEN'
colorCode = '#00FF00'
} else {
colorName = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend (color: colorCode, message: summary, channel: "citibank-project")
}