启动jenkins:(如果默认启动Jenkins的用户已经替换为你自己的用户,则不需要sudo)
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
停止jenkins:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
项目pom文件配置:添加依赖
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.13.2</version>
<exclusions>
<exclusion>
<artifactId>testng</artifactId>
<groupId>org.testng</groupId>
</exclusion>
</exclusions>
</dependency>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.5/aspectjweaver-1.9.5.jar"
</argLine>
<suiteXmlFiles>
<suiteXmlFile>./src/test/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
jenkins配置相关:
插件:Allure Jenkins Plugin、Email Extension Plugin、Extended Choice Parameter Plug-In、HTML Publisher plugin、Role-based Authorization Strategy及其安装时的默认插件
系统配置:Configure System
全局参数配置:Global Tool Configuration
新建项目后,配置:
比较好的邮件内容模板:
<!-- 比较好的邮件模板 -->
<!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">项目描述:${JOB_DESCRIPTION}</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>构建状态:$BUILD_STATUS</li>
<li>触发原因:${CAUSE}</li>
<li>项目地址:<a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
<li>构建地址:<a href="${BUILD_URL}">${BUILD_URL}</a></li>
<li>构建日志:<a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
<li>系统测试报告:<A HREF="${PROJECT_URL}${BUILD_NUMBER}/allure">${PROJECT_URL}${BUILD_NUMBER}/allure</a></li>
<li>变更集:${JELLY_SCRIPT,template="html"}</li>
</ul>
</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><textarea cols="80" rows="30" readonly="readonly"
style="font-family: Courier New">${BUILD_LOG, maxLines=100}</textarea>
</td>
</tr>
</table>
</body>
</html>
结果Demo:
可能遇到的问题:
1、可能需要建立软连接:sudo ln -s /Users/you/app/apache-maven-3.6.1/bin/mvn /usr/bin/mvn (你自己的mvn安装地址)
2、git拖取代码授权认证问题:将启动Jenkins的配置用户信息改为自己用户账号或root(如步骤3,4,5)
3、sudo vim /Library/LaunchDaemons/org.jenkins-ci.plist
4、sudo chown -R youName:wheel /Users/Shared/Jenkins/
5、sudo chown -R youName:wheel /var/log/jenkins/