Add production email notification pipeline
This commit is contained in:
69
jenkins/Jenkinsfile.production-notify-email
Normal file
69
jenkins/Jenkinsfile.production-notify-email
Normal file
@@ -0,0 +1,69 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'linux && genarrative-build'
|
||||
}
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
skipDefaultCheckout(true)
|
||||
buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '0'))
|
||||
}
|
||||
|
||||
parameters {
|
||||
string(name: 'EMAIL_RECIPIENTS', defaultValue: '', description: '本次运行追加邮件通知收件人;会与 Jenkins 全局环境变量 GENARRATIVE_NOTIFICATION_EMAILS 合并发送')
|
||||
string(name: 'SOURCE_JOB_NAME', defaultValue: '', description: '来源流水线名称')
|
||||
string(name: 'SOURCE_BUILD_NUMBER', defaultValue: '', description: '来源构建号')
|
||||
string(name: 'SOURCE_BUILD_URL', defaultValue: '', description: '来源构建 URL')
|
||||
string(name: 'SOURCE_RESULT', defaultValue: 'UNKNOWN', description: '来源流水线结果')
|
||||
string(name: 'SOURCE_BRANCH', defaultValue: '', description: '源码分支')
|
||||
string(name: 'SOURCE_COMMIT', defaultValue: '', description: '源码 commit')
|
||||
string(name: 'BUILD_VERSION', defaultValue: '', description: '发布版本号')
|
||||
string(name: 'DEPLOY_TARGET', defaultValue: '', description: '部署目标')
|
||||
string(name: 'DATABASE', defaultValue: '', description: 'SpacetimeDB database')
|
||||
string(name: 'SUMMARY', defaultValue: '', description: '补充摘要')
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Send Email') {
|
||||
steps {
|
||||
script {
|
||||
def recipientList = []
|
||||
[env.GENARRATIVE_NOTIFICATION_EMAILS, params.EMAIL_RECIPIENTS].each { rawRecipients ->
|
||||
rawRecipients?.split(',')?.each { recipient ->
|
||||
def normalized = recipient.trim()
|
||||
if (normalized && !recipientList.contains(normalized)) {
|
||||
recipientList.add(normalized)
|
||||
}
|
||||
}
|
||||
}
|
||||
def recipients = recipientList.join(',')
|
||||
if (!recipients) {
|
||||
echo '[notify-email] EMAIL_RECIPIENTS 与 GENARRATIVE_NOTIFICATION_EMAILS 均未配置,跳过邮件发送。'
|
||||
return
|
||||
}
|
||||
|
||||
def result = params.SOURCE_RESULT?.trim() ?: 'UNKNOWN'
|
||||
def jobName = params.SOURCE_JOB_NAME?.trim() ?: 'unknown-job'
|
||||
def buildNumber = params.SOURCE_BUILD_NUMBER?.trim() ?: 'unknown-build'
|
||||
def subject = "[Genarrative][${result}] ${jobName} #${buildNumber}"
|
||||
def body = """Genarrative Jenkins 流水线执行结果
|
||||
|
||||
结果: ${result}
|
||||
流水线: ${jobName}
|
||||
构建号: ${buildNumber}
|
||||
构建 URL: ${params.SOURCE_BUILD_URL ?: ''}
|
||||
源码分支: ${params.SOURCE_BRANCH ?: ''}
|
||||
源码 commit: ${params.SOURCE_COMMIT ?: ''}
|
||||
发布版本: ${params.BUILD_VERSION ?: ''}
|
||||
部署目标: ${params.DEPLOY_TARGET ?: ''}
|
||||
数据库: ${params.DATABASE ?: ''}
|
||||
摘要: ${params.SUMMARY ?: ''}
|
||||
"""
|
||||
|
||||
mail to: recipients, subject: subject, body: body
|
||||
echo "[notify-email] 已发送邮件: recipients=${recipients}, source=${jobName} #${buildNumber}, result=${result}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user