-
Notifications
You must be signed in to change notification settings - Fork 20
/
Jenkinsfile
167 lines (161 loc) · 7.33 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
pipeline {
agent any
environment {
GIT_REPO_URL = 'https://github.com/vigneshshettyin/EatMyURL.git'
GIT_BRANCH = 'main'
IMAGE_NAME = 'eurl-api'
DOCKER_CREDENTIALS = credentials('dockerHub')
CLICKHOUSE_URL = credentials('CLICKHOUSE_URL')
RABBITMQ_URI = credentials('RABBITMQ_URI')
REDIS_URI = credentials('REDIS_URI')
SECRET_KEY = credentials('SECRET_KEY')
DOCKER_REPO = "${DOCKER_CREDENTIALS_USR}/eurl-api:latest"
}
stages {
stage('Pull Code') {
steps {
git url: env.GIT_REPO_URL, branch: env.GIT_BRANCH
}
}
stage('Build') {
steps {
sh "cd kafka-clickhouse && docker build -t ${env.IMAGE_NAME} ."
}
}
stage('Push Image') {
steps {
sh "docker tag ${env.IMAGE_NAME} ${DOCKER_REPO}"
sh('docker login -u $DOCKER_CREDENTIALS_USR -p $DOCKER_CREDENTIALS_PSW')
sh "docker push ${DOCKER_REPO}"
}
}
stage('Deploy Container') {
steps {
sh "docker compose down && docker compose up -d"
}
}
}
post {
always {
sh 'rm -f *.log'
sh 'rm -f *.txt'
script {
def logContent = currentBuild.rawBuild.getLog(1000).join("\n")
writeFile file: 'console_output.txt', text: logContent
archiveArtifacts artifacts: 'console_output.txt', allowEmptyArchive: true
}
sh "docker logout"
sh "docker system prune -af"
sh "docker volume prune -f"
emailext (
subject: "Build ${currentBuild.fullDisplayName}: ${currentBuild.currentResult}",
body: """
<html>
<head>
<style>
body { font-family: Arial, sans-serif; color: #333333; }
.email-header {
background-color: #333333;
color: #ffffff;
padding: 15px;
text-align: center;
}
.email-header img {
width: 50px;
vertical-align: middle;
margin-right: 10px;
}
.email-header h2 {
display: inline;
font-size: 20px;
}
.build-status-card {
padding: 10px;
color: #ffffff;
font-size: 16px;
border-radius: 5px;
width: fit-content;
margin: 10px auto;
text-align: center;
}
.success-card { background-color: #4CAF50; }
.failure-card { background-color: #F44336; }
.build-details {
width: 100%;
margin-top: 20px;
}
.build-details table {
width: 100%;
border-collapse: collapse;
}
.build-details th, .build-details td {
border: 1px solid #dddddd;
padding: 8px;
text-align: left;
}
.build-details th {
background-color: #f2f2f2;
}
.footer {
margin-top: 30px;
font-size: 12px;
color: #555555;
text-align: center;
}
</style>
</head>
<body>
<!-- Email Header with Logo -->
<div class="email-header">
<img src="https://www.jenkins.io/images/logos/jenkins/jenkins.png" alt="Jenkins Logo" />
<h2>Jenkins Build Notification</h2>
</div>
<!-- Build Status -->
<div class="build-status-card ${currentBuild.currentResult == 'SUCCESS' ? 'success-card' : 'failure-card'}">
<b>Build Status:</b> ${currentBuild.currentResult}
</div>
<!-- Build Details in Table Format -->
<div class="build-details">
<table>
<tr>
<th>Project</th>
<td>EatMyURL API v2</td>
</tr>
<tr>
<th>Build Number</th>
<td>${env.BUILD_NUMBER}</td>
</tr>
<tr>
<th>Branch</th>
<td>${GIT_BRANCH}</td>
</tr>
<tr>
<th>Duration</th>
<td>${currentBuild.durationString}</td>
</tr>
<tr>
<th>Changes</th>
<td>${currentBuild.changeSets.collect { it.items.collect { it.msg } }.flatten().join('<br>')}</td>
</tr>
<tr>
<th>Build URL</th>
<td><a href="${env.BUILD_URL}">${env.BUILD_URL}</a></td>
</tr>
</table>
</div>
<!-- Footer -->
<div class="footer">
<p>Best regards,<br><b>Jenkins CI/CD</b></p>
<p>Attached logs, if any, can be found below.</p>
</div>
</body>
</html>
""",
mimeType: 'text/html',
from: 'Jenkins <build@vshetty.dev>',
to: 'jenkins+vignesh@vshetty.dev, vijeshsshetty@gmail.com',
attachmentsPattern: 'console_output.txt'
)
}
}
}