jenkins配置

jenkins配置

下载tomcat

http://tomcat.apache.org/

配置tomcat的环境变量

CATALINA_HOME E:\apache-tomcat  
path E:\apache-tomcat\bin;E:\apache-tomcat\lib

 

下载jenkins

https://jenkins.io/zh/download/ #下载较慢

将下载好的jenkines.war放到tomcat的webapps下

启动在/lib/start.bat

 

修改为阿里源

C:\Users\JunJie\.jenkins 下的 hudson.model.UpdateCenter.xml
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.json

 

输入网址:

http://localhost:8080/jenkins

 

安装推荐的插件:

 

使用Jenkins

 

 

 

 

 

 

JDK 和maven配置

在插件中点击Global Tool Configuration

构建mvn项目

需要先安装插件maven integration

第一步:

第二步:

增加代码源:

git或者svn都可以

 

第三步:

增加执行器

 

a.针对mvn的项目(执行后,需要运行的mvn项目,如clean package install 等)

b.cmd中运行的指令(如运行jar包)

testng运行方法

需要增加mvn插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>

<configuration>
<!-- 忽略测试套件执行过程中失败的测试方法,继续执行剩余的测试类和测试方法 -->
<testFailureIgnore>true</testFailureIgnore>
<!-- 指定构建(执行套件)时要执行的套件的文件路径 -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>

</configuration>
</plugin>

 

 

邮件自动发送

1.安装插件Email Extension Template Plugin

2。配置Extended E-mail Notification

 

 

邮件正文代码:

<!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 class="table" width="1000" border="1" cellspacing="0" cellpadding="5">
   <caption align="center"><h3>项目构建信息</h3></caption>
   <thead>
   <tr>
       <th>构建项目-<b>${PROJECT_NAME}</b></th>
   </tr>
   </thead>
   <tbody>
   <tr>
       <td><font color="#CC0000"><b>构建结果 - ${BUILD_STATUS}</b></font></td>
   </tr>
   <tr>
       <td>测试数量-${TEST_COUNTS, var="total"}</td>
   </tr>
   </tbody>
   <tr>
      本邮件由系统自动发出,无需回复!<br/>
      各位同事,大家好,以下为${PROJECT_NAME}项目构建信息</br>
   </tr>

   <tr>
       <td><br/>
           <b><font color="#0B610B">构建报告</font></b>
           <hr size="2" width="100%" align="center"/>
           <ul>
               <li>构建报告:<a href="${BUILD_URL}allure/">${PROJECT_URL}allure/</li>
           </ul>
       </td>
   </tr>
   <tr>
       <td><br/>
           <b><font color="#0B610B">构建信息</font></b>
           <hr size="2" width="100%" align="center"/>
           <ul>
               <li>项目名称: ${PROJECT_NAME}</li>
               <li>构建编号: 第${BUILD_NUMBER}次构建</li>
               <li>触发原因:${CAUSE}</li>
               <li>构建状态:${BUILD_STATUS}</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">构建详细信息</font></b>
           <hr size="2" width="100%" align="center"/>
           <ul>
               <li>BRANCH_NAME: ${BRANCH_NAME}</li>
               <li>CHANGE_ID: ${CHANGE_ID}</li>
               <li>CHANGE_URL: ${CHANGE_URL}</li>
               <li>CHANGE_TITLE: ${CHANGE_TITLE}</li>
               <li>CHANGE_AUTHOR: ${CHANGE_AUTHOR}</li>
               <li>CHANGE_AUTHOR_DISPLAY_NAME: ${CHANGE_AUTHOR_DISPLAY_NAME}</li>
               <li>CHANGE_AUTHOR_EMAIL: ${CHANGE_AUTHOR_EMAIL}</li>
               <li>CHANGE_TARGET: ${CHANGE_TARGET}</li>
               <li>BUILD_NUMBER: ${BUILD_NUMBER}</li>
               <li>BUILD_DISPLAY_NAME: ${BUILD_DISPLAY_NAME}</li>
               <li>BUILD_ID: ${BUILD_ID}</li>
               <li>JOB_NAME: ${JOB_NAME}</li>
               <li>JOB_BASE_NAME: ${JOB_BASE_NAME}</li>
               <li>BUILD_TAG: ${BUILD_TAG}</li>
               <li>EXECUTOR_NUMBER: ${EXECUTOR_NUMBER}</li>
               <li>NODE_NAME: ${NODE_NAME}</li>
               <li>NODE_LABELS: ${NODE_LABELS}</li>
               <li>WORKSPACE: ${WORKSPACE}</li>
               <li>JENKINS_HOME: ${JENKINS_HOME}</li>
               <li>JENKINS_URL: ${JENKINS_URL}</li>
               <li>BUILD_URL: ${BUILD_URL}</li>
               <li>JOB_URL: ${JOB_URL}</li>
               <li>GIT_COMMIT: ${GIT_COMMIT}</li>
               <li>GIT_PREVIOUS_COMMIT: ${GIT_PREVIOUS_COMMIT}</li>
               <li>GIT_PREVIOUS_SUCCESSFUL_COMMIT: ${GIT_PREVIOUS_SUCCESSFUL_COMMIT}</li>
               <li>GIT_BRANCH: ${GIT_BRANCH}</li>
               <li>GIT_LOCAL_BRANCH: ${GIT_LOCAL_BRANCH}</li>
               <li>GIT_URL: ${GIT_URL}</li>
               <li>GIT_COMMITTER_NAME: ${GIT_COMMITTER_NAME}</li>
               <li>GIT_AUTHOR_NAME: ${GIT_AUTHOR_NAME}</li>
               <li>GIT_COMMITTER_EMAIL: ${GIT_COMMITTER_EMAIL}</li>
               <li>GIT_AUTHOR_EMAIL: ${GIT_AUTHOR_EMAIL}</li>
               <li>MERCURIAL_REVISION: ${MERCURIAL_REVISION}</li>
               <li>MERCURIAL_REVISION_SHORT: ${MERCURIAL_REVISION_SHORT}</li>
               <li>MERCURIAL_REVISION_NUMBER: ${MERCURIAL_REVISION_NUMBER}</li>
               <li>MERCURIAL_REVISION_BRANCH: ${MERCURIAL_REVISION_BRANCH}</li>
               <li>MERCURIAL_REPOSITORY_URL: ${MERCURIAL_REPOSITORY_URL}</li>
               <li>SVN_REVISION: ${SVN_REVISION}</li>
               <li>SVN_URL: ${SVN_URL}</li>
           </ul>
       </td>
   </tr>
   <tr>
       <td>
           <h4><font color="#0B610B">失败用例</font></h4>
          ${FAILED_TESTS}<br/>
       </td>
   </tr>

   <tr>
       <td>
           <h4><font color="#0B610B">最近提交(#$GIT_REVISION)</font></h4>
           <!--
           <ul>
               ${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="
               <li>%d [%a] %m</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>
                  上次构建成功后变化 : ${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}
               </li>
           </ul>
       </td>
   </tr>
   <tr>
       <td>
           <ul>
               <li>上次构建不稳定后变化 : ${CHANGES_SINCE_LAST_UNSTABLE, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}
               </li>
           </ul>
       </td>
   <tr>
       <td>
           <ul>
               <li>历史变更记录 : <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a></li>
           </ul>
       </td>
   </tr>
   <tr>
       <td>
           <ul>
               <li>变更集:${JELLY_SCRIPT,template="html"}</li>
           </ul>
       </td>
   </tr>
   <tr>
       <td><b><font color="#0B610B">构建日志:</font></b>
           <hr size="2" width="100%" align="center"/>
       </td>
   </tr>
   <tr>
       <td><textarea cols="120" rows="30" readonly="readonly"
                     style="font-family: Courier New">${BUILD_LOG}</textarea>
       </td>
   </tr>
</table>
</body>
</html>

 

 

3.配置Jenkins自带的邮件功能

 

4.构建项目邮件配置

定时构建任务

• 1.每30分钟构建一次:
• H/30 * * * *
• 2.每2个小时构建一次
• H H/2 * * *
• 3.每天早上8点构建一次
• 0 8 * * *
• 4.每天的8点,12点,22点,一天构建3次
• 0 8,12,22 * * *

 

posted @ 2020-04-28 11:10  测开工程师成长之路  阅读(202)  评论(0编辑  收藏  举报