Jenkins常用配置
阿新 • • 發佈:2020-08-05
Plugins: Email Extension Template
Pipeline email 配置段
先利用Declarative Directive Generator生成 Post stage程式碼段
post {
always {
// One or more steps need to be included within each condition's block.
}
}
在利用Snippet Generator生成emailext段程式碼
pipeline {
agent any
stages {
stage( 'Pull Code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'cb8cbf69-e68c-4e8c-8fbe-f252e27f591b', url: '[email protected]:colon1/project1.git ']]])
}
}
stage('Build Project') {
steps {
sh label: '', script: 'mvn clean package'
}
}
stage('Publish Project') {
steps {
deploy adapters: [tomcat9(credentialsId: 'aac586c5-9c9b-4d2f-9d04-e20aa6d2bcd2 ', path: '', url: 'http://192.168.8.8:8080')], contextPath: null, war: 'target/*.war'
}
}
}
post {
always {
emailext body: '${FILE,path="/opt/email.html"}', subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!', to: '[email protected],[email protected]'
}
}
}
可用郵件模板
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次構建日誌</title>
</head>
<body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4" offset="0">
<table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">
<tr>
<td>(本郵件是程式自動下發的,請勿回覆!)</td>
</tr>
<tr>
<td><h2><font color="#0000FF">構建結果 - ${BUILD_STATUS}</font></h2></td>
</tr>
<tr>
<td><br /> <b><font color="#0B610B">構建資訊</font></b> <hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td>
<ul>
<li>專案名稱 : ${PROJECT_NAME}</li>
<li>構建編號 : 第${BUILD_NUMBER}次構建</li>
<li>觸發原因: ${CAUSE}</li>
<li>構建日誌: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>構建 Url : <a href="${BUILD_URL}">${BUILD_URL}</a></li>
<li>工作目錄 : <a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>
<li>專案 Url : <a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
</ul>
</td>
</tr>
<tr>
<td>
<b><font color="#0B610B">Changes Since Last Successful Build:</font></b>
<hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<ul>
<li>歷史變更記錄 : <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a></li>
</ul></td>
</tr>
<tr>
<td>
<b>Failed Test Results</b> <hr size="2" width="100%" align="center" />
</td>
</tr>
<tr>
<td>
<pre style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">$FAILED_TESTS</pre> <br />
</td>
</tr>
<tr>
<td><b><font color="#0B610B">構建日誌 (最後 100行):</font></b> <hr size="2" width="100%" align="center" /></td>
</tr> <!-- <tr> <td>Test Logs (if test has ran): <a href="${PROJECT_URL}ws/TestResult/archive_logs/Log-Build-${BUILD_NUMBER}.zip">${PROJECT_URL}/ws/TestResult/archive_logs/Log-Build-${BUILD_NUMBER}.zip</a> <br /> <br /> </td> </tr> -->
<tr>
<td>
<textarea cols="80" rows="30" readonly="readonly" style="font-family: Courier New">${BUILD_LOG, maxLines=100}</textarea>
</td>
</tr>
</table>
</body>
</html>
View Code