-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathJenkinsfile
89 lines (81 loc) · 2.21 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
pipeline {
agent any
tools{
maven "maven3"
jdk "jdk17"
}
environment{
SCANNER_HOME = tool 'sonar-token'
}
stages{
stage("Code Checkout"){
steps{
git branch: 'main', url: 'https://github.com/Cloud-Gen-DevOps-Projects/Rigstration-Form.git'
}
}
stage("Code Qulity Check"){
steps{
withSonarQubeEnv('sonar-token') {
sh "mvn clean install sonar:sonar"
}
}
}
stage("Package Build"){
steps{
sh "mvn package"
}
}
stage("Package Deploy"){
steps{
sh "mvn deploy"
}
}
stage("Docker Image Build"){
steps{
sh "docker build -t cloudgen01/registration-form:latest ."
}
}
stage("Docker Image Upload into Docker Registry"){
steps{
withDockerRegistry(credentialsId: 'Docker-Cloudgen01', url: 'https://index.docker.io/v1/') {
sh "docker push cloudgen01/registration-form:latest"
}
}
}
}
post {
always {
script {
// Get job name, build number, and pipeline status
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER
def pipelineStatus = currentBuild.result ?: 'UNKNOWN'
pipelineStatus = pipelineStatus.toUpperCase()
// Set the banner color based on the status
def bannerColor = pipelineStatus == 'SUCCESS' ? 'green' : 'red'
// HTML body for the email
def body = """
<body>
<div style="border: 2px solid ${bannerColor}; padding: 10px;">
<h3 style="color: ${bannerColor};">
Pipeline Status: ${pipelineStatus}
</h3>
<p>Job: ${jobName}</p>
<p>Build Number: ${buildNumber}</p>
<p>Status: ${pipelineStatus}</p>
</div>
</body>
"""
// Send email notification
emailext(
subject: "${jobName} - Build ${buildNumber} - ${pipelineStatus}",
body: body,
to: '[email protected]',
from: '[email protected]',
replyTo: '[email protected]',
mimeType: 'text/html'
)
}
}
}
}