Merge pull request '[1.0.1]' (#20) from dev into main

Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
2026-04-30 19:20:58 +00:00
2 changed files with 80 additions and 85 deletions
Vendored
+2 -2
View File
@@ -152,7 +152,7 @@ pipeline {
subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} succeeded", subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} succeeded",
body: renderEmail('Build succeeded', '#16a34a', buildInfo()), body: renderEmail('Build succeeded', '#16a34a', buildInfo()),
mimeType: 'text/html', mimeType: 'text/html',
to: 'admin@msigmagokulam.com, ashir@mgsigma.net' to: 'admin@msigmagokulam.com, ashir@mgsigma.net, kailasdevdas@msigmagokulam.com'
) )
} }
} }
@@ -162,7 +162,7 @@ pipeline {
subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} failed", subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} failed",
body: renderEmail('Build failed', '#dc2626', buildInfo()), body: renderEmail('Build failed', '#dc2626', buildInfo()),
mimeType: 'text/html', mimeType: 'text/html',
to: 'admin@msigmagokulam.com, ashir@mgsigma.net' to: 'admin@msigmagokulam.com, ashir@mgsigma.net, kailasdevdas@msigmagokulam.com'
) )
} }
} }
+78 -83
View File
@@ -89,7 +89,7 @@ pipeline {
steps { steps {
sshagent (credentials: ["${env.SSH_CREDENTIALS_ID}"]) { sshagent (credentials: ["${env.SSH_CREDENTIALS_ID}"]) {
sh """ sh """
ssh -o StrictHostKeyChecking=no \$REMOTE_HOST 'mkdir -p \$REMOTE_DEPLOY_DIR' ssh -o StrictHostKeyChecking=no $REMOTE_HOST 'mkdir -p $REMOTE_DEPLOY_DIR'
rsync -az --delete \\ rsync -az --delete \\
--exclude='.git/' \\ --exclude='.git/' \\
--exclude='node_modules/' \\ --exclude='node_modules/' \\
@@ -97,7 +97,7 @@ pipeline {
--exclude='frontend/node_modules/' \\ --exclude='frontend/node_modules/' \\
--exclude='frontend/dist/' \\ --exclude='frontend/dist/' \\
-e "ssh -o StrictHostKeyChecking=no" \\ -e "ssh -o StrictHostKeyChecking=no" \\
./ \$REMOTE_HOST:\$REMOTE_DEPLOY_DIR/ ./ $REMOTE_HOST:$REMOTE_DEPLOY_DIR/
""" """
} }
} }
@@ -107,9 +107,9 @@ pipeline {
steps { steps {
sshagent (credentials: ["${env.SSH_CREDENTIALS_ID}"]) { sshagent (credentials: ["${env.SSH_CREDENTIALS_ID}"]) {
sh """ sh """
ssh -o StrictHostKeyChecking=no \$REMOTE_HOST ' ssh -o StrictHostKeyChecking=no $REMOTE_HOST '
set -e set -e
cd \$REMOTE_DEPLOY_DIR cd $REMOTE_DEPLOY_DIR
if [ -n "\$(docker compose -f $COMPOSE_FILE ps -q 2>/dev/null)" ]; then if [ -n "\$(docker compose -f $COMPOSE_FILE ps -q 2>/dev/null)" ]; then
echo "[INFO] Stopping existing containers..." echo "[INFO] Stopping existing containers..."
@@ -130,96 +130,91 @@ pipeline {
} }
post { post {
always {
script {
env.BUILD_INFO_HASH = sh(
script: "git rev-parse --short HEAD 2>/dev/null || echo N/A",
returnStdout: true
).trim()
env.BUILD_INFO_AUTHOR = sh(
script: "git log -1 --pretty=format:'%an' 2>/dev/null || echo N/A",
returnStdout: true
).trim()
env.BUILD_INFO_MESSAGE = sh(
script: "git log -1 --pretty=format:'%s' 2>/dev/null || echo 'No commit message found'",
returnStdout: true
).trim()
def cause = currentBuild.getBuildCauses()?.getAt(0)?.shortDescription ?: 'Unknown'
env.BUILD_INFO_TRIGGER = cause.contains('Started by user') ? 'Manual trigger' : cause
}
}
success { success {
script { script {
def causes = currentBuild.getBuildCauses() emailext(
def triggeredBy = causes ? causes[0].shortDescription : "Unknown" subject: "[PRODUCTION] ${env.JOB_NAME} #${env.BUILD_NUMBER} succeeded",
def isManual = triggeredBy.contains('Started by user') body: renderEmail('Build succeeded', '#16a34a', buildInfo()),
def commitHash = sh(script: "git rev-parse --short HEAD", returnStatus: true) == 0 ?
sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() : "N/A"
def commitAuthor = sh(script: "git log -1 --pretty=format:%an", returnStatus: true) == 0 ?
sh(script: "git log -1 --pretty=format:%an", returnStdout: true).trim() : "N/A"
def commitMessage = sh(script: "git log -1 --pretty=format:%s", returnStatus: true) == 0 ?
sh(script: "git log -1 --pretty=format:%s", returnStdout: true).trim() : "No commit message found"
def envInfo = """
<ul>
<li><strong>Environment:</strong> <span style="color:#087d6b">Production</span></li>
<li><strong>Deployed By:</strong> ${isManual ? 'Manual Trigger' : triggeredBy}</li>
<li><strong>Deploy Time:</strong> ${new Date().format('yyyy-MM-dd HH:mm:ss', java.util.TimeZone.getTimeZone('Asia/Kolkata'))}</li>
</ul>
"""
emailext (
subject: "[PRODUCTION] SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: """
<div style="font-family:Arial,sans-serif;">
<h2 style="color:#037235;">Production Deployment Successful</h2>
${envInfo}
<p><strong>Commit Info:</strong></p>
<ul>
<li><strong>Hash:</strong> ${commitHash}</li>
<li><strong>Author:</strong> ${commitAuthor}</li>
<li><strong>Message:</strong> ${commitMessage}</li>
</ul>
<p>Review the output here:</p>
<p>
<a href="${env.BUILD_URL}" style="display:inline-block; margin-top:10px; color:#fff; background:#28a745; text-decoration:none; padding:10px 20px; border-radius:4px;">View Build Log</a>
</p>
<hr>
<p style="font-size:small; color:#6c757d;">Production deployment via Jenkins. Contact DevOps for any issues.</p>
</div>
""",
mimeType: 'text/html', mimeType: 'text/html',
to: 'admin@msigmagokulam.com, ashir@mgsigma.net, ajiahamed@msigmagokulam.com, arjunsthampi@mgsigma.net' to: 'admin@msigmagokulam.com, ashir@mgsigma.net, kailasdevdas@msigmagokulam.com'
) )
} }
} }
failure { failure {
script { script {
def causes = currentBuild.getBuildCauses() emailext(
def triggeredBy = causes ? causes[0].shortDescription : "Unknown" subject: "[PRODUCTION] ${env.JOB_NAME} #${env.BUILD_NUMBER} failed",
def isManual = triggeredBy.contains('Started by user') body: renderEmail('Build failed', '#dc2626', buildInfo()),
def commitHash = sh(script: "git rev-parse --short HEAD", returnStatus: true) == 0 ?
sh(script: "git rev-parse --short HEAD", returnStdout: true).trim() : "N/A"
def commitAuthor = sh(script: "git log -1 --pretty=format:%an", returnStatus: true) == 0 ?
sh(script: "git log -1 --pretty=format:%an", returnStdout: true).trim() : "N/A"
def commitMessage = sh(script: "git log -1 --pretty=format:%s", returnStatus: true) == 0 ?
sh(script: "git log -1 --pretty=format:%s", returnStdout: true).trim() : "No commit message found"
def envInfo = """
<ul>
<li><strong>Environment:</strong> <span style="color:#c82333">Production</span></li>
<li><strong>Deployed By:</strong> ${isManual ? 'Manual Trigger' : triggeredBy}</li>
<li><strong>Deploy Time:</strong> ${new Date().format('yyyy-MM-dd HH:mm:ss', java.util.TimeZone.getTimeZone('Asia/Kolkata'))}</li>
</ul>
"""
emailext (
subject: "[PRODUCTION] FAILURE: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: """
<div style="font-family:Arial,sans-serif;">
<h2 style="color:#b21f2d;">Production Deployment Failed</h2>
${envInfo}
<p><strong>Commit Info:</strong></p>
<ul>
<li><strong>Hash:</strong> ${commitHash}</li>
<li><strong>Author:</strong> ${commitAuthor}</li>
<li><strong>Message:</strong> ${commitMessage}</li>
</ul>
<p>Review error logs here:</p>
<p>
<a href="${env.BUILD_URL}" style="display:inline-block; margin-top:10px; color:#fff; background:#28a745; text-decoration:none; padding:10px 20px; border-radius:4px;">View Build Log</a>
</p>
<hr>
<p style="font-size:small; color:#6c757d;">Production deployment via Jenkins. Contact DevOps for any issues.</p>
</div>
""",
mimeType: 'text/html', mimeType: 'text/html',
to: 'admin@msigmagokulam.com, ashir@mgsigma.net, ajiahamed@msigmagokulam.com, arjunsthampi@mgsigma.net' to: 'admin@msigmagokulam.com, ashir@mgsigma.net, kailasdevdas@msigmagokulam.com'
) )
} }
} }
} }
} }
def buildInfo() {
return [
hash: env.BUILD_INFO_HASH ?: 'N/A',
author: env.BUILD_INFO_AUTHOR ?: 'N/A',
message: env.BUILD_INFO_MESSAGE ?: 'N/A',
trigger: env.BUILD_INFO_TRIGGER ?: 'Unknown',
duration: currentBuild.durationString.replace(' and counting', '')
]
}
def renderEmail(String label, String accent, Map info) {
return """\
<!DOCTYPE html>
<html>
<body style="margin:0; padding:0; background-color:#f6f7f9;">
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#f6f7f9; padding:40px 16px;">
<tr><td align="center">
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="560" style="max-width:560px; background:#ffffff; border-radius:12px; overflow:hidden; box-shadow:0 1px 3px rgba(15,23,42,0.08); font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;">
<tr><td style="height:3px; background:${accent};"></td></tr>
<tr><td style="padding:32px 40px 0 40px;">
<div style="font-size:12px; font-weight:600; color:${accent}; letter-spacing:0.8px; text-transform:uppercase; margin-bottom:6px;">${label} · production</div>
<div style="font-size:20px; font-weight:600; color:#0f172a; line-height:1.35;">${env.JOB_NAME}<span style="color:#94a3b8; font-weight:400;"> &middot; #${env.BUILD_NUMBER}</span></div>
</td></tr>
<tr><td style="padding:20px 40px 8px 40px;">
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="font-size:14px; color:#0f172a;">
<tr><td width="110" style="padding:7px 0; color:#64748b;">Commit</td><td style="padding:7px 0; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:13px;">${info.hash}</td></tr>
<tr><td style="padding:7px 0; color:#64748b;">Author</td><td style="padding:7px 0;">${info.author}</td></tr>
<tr><td style="padding:7px 0; color:#64748b; vertical-align:top;">Message</td><td style="padding:7px 0;">${info.message}</td></tr>
<tr><td style="padding:7px 0; color:#64748b;">Triggered by</td><td style="padding:7px 0;">${info.trigger}</td></tr>
<tr><td style="padding:7px 0; color:#64748b;">Duration</td><td style="padding:7px 0;">${info.duration}</td></tr>
</table>
</td></tr>
<tr><td style="padding:20px 40px 32px 40px;">
<a href="${env.BUILD_URL}" style="display:inline-block; padding:10px 18px; background:#0f172a; color:#ffffff; text-decoration:none; border-radius:8px; font-size:14px; font-weight:500;">View build</a>
<a href="${env.BUILD_URL}console" style="display:inline-block; padding:10px 14px; color:#475569; text-decoration:none; font-size:14px; font-weight:500;">Console output &rarr;</a>
</td></tr>
<tr><td style="padding:14px 40px; background:#f8fafc; border-top:1px solid #e2e8f0; font-size:12px; color:#94a3b8;">
Automated notification from Jenkins
</td></tr>
</table>
</td></tr>
</table>
</body>
</html>
"""
}