jenkins教程:https://www.jenkins.io/zh/doc/book/pipeline/getting-started/
1.建立一個流水線任務
2.在配置中--流水線--定義pipeline流水線腳本,如下:
pipeline {
agent any
stages {
stage("獲取git master") {
agent {
label "master"
}
steps {
git url: 'https://053ef307***@github.com/vt.git', branch: 'master'
}
}
stage("執行用例") {
agent {
docker {
label "master"
image 'python3_pytest:lastest'
args ''
}
}
steps {
sh 'pytest ./testcase/ --env dev1 --html ./report/api_dev.html --junit-xml ./report/api_dev.xml'
}
post {
always {
// txt測試報告
junit 'report/api_dev.xml'
// html測試報告
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: './report',
reportFiles: 'api_dev.html',
reportName: "API DEV Report"
])
}
}
}
}
post {
always {
echo currentBuild.result
}
success {
echo "success"
// emailext body: '$DEFAULT_CONTENT', subject: '$DEFAULT_SUBJECT', to: '$DEFAULT_RECIPIENTS'
}
failure {
echo "failure"
emailext body: '$DEFAULT_CONTENT', subject: '$DEFAULT_SUBJECT', to: '$DEFAULT_RECIPIENTS'
}
}
}
這是一個3個步驟的流水線,第一拉取GitHub代碼,第二啟動鏡像(Jenkins節點上docker的鏡像)執行shell,運行用例,第三發送報告
Jenkins教程:https://blog.csdn.net/kefengwang/article/details/54233584
郵件配置:
<!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>(本郵件是Jenkins程序自動下發的,請勿回復!)</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>構建地址:<a href="${BUILD_URL}">${BUILD_URL}</a></li>
<li>工作目錄:<a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>
<li>項目地址:<a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
<li>測試報告:<a href="${BUILD_URL}testReport/">${BUILD_URL}testReport/</a></li>
</ul>
</td>
</tr>
<tr>
<td><b><font color="#0B610B">測試結果:</font></b>
<hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td>
<ul>
<li>Total:${TEST_COUNTS,var="total"}</li>
<li>Pass:${TEST_COUNTS,var="pass"}</li>
<li>Failed:${TEST_COUNTS,var="fail"}</li>
<li>Skiped:${TEST_COUNTS,var="skip"}</li>
</ul>
<br />
</td>
</tr>
<tr>
<td><b><font color="#0B610B">構建日志 (最后 100行):</font></b>
<hr size="2" width="100%" align="center" /></td>
</tr>
<tr>
<td><textarea cols="100" rows="30" readonly="readonly"
style="font-family: Courier New;width: 888px">${BUILD_LOG, maxLines=100}</textarea>
</td>
</tr>
</table>
</body>
</html>
