持续集成 jenkins 集成测试工作流程

周小丽 · 2016年04月22日 · 最后由 ruanjiancaipu 回复于 2018年09月12日 · 5176 次阅读

最近研究了下 jenkins,将自己所了解的整理个文档,有不足的请大伙多指教。

先说下项目在 jenkins 上具体的开发、测试、部署流程

  1. 当开发新功能或修改 bug 时,一般是在分支上执行;当开发自测通过后会 merge 到 master.
  2. 当 master 有变动时,会自动触发 build 构建任务(当然也可以定时触发),执行集成的单元测试(目前弱化了单元测试),代码质量静态检测,若 build 不通过则触发邮件给 developer.
  3. 若编译和测试环境不一致,或为了减轻主服务器的压力,可创建子节点服务执行 test 任务,进行自动化冒烟测试,若测试不通过则触发邮件给 tester.
  4. 若冒烟测试通过,则进行人工测试,若测试通过则手动触发 deploy 任务部署到生产服务器上进行相关测试.

接下来说下项目在 jenkins 上具体的应用

jenkins 的基础配置

环境搭建

  1. JDK 下载与配置环境变量 (win 运行 cmd,输入 java -version 查看是否输出 java version,如果输出成功则证明配置 JDK 正确)
  2. SDK 下载与配置环境变量 (win 运行 cmd,输入 adb start-server 查看是否成功启动 adb server,如果成功则证明 SDK 配成功)
  3. GIT 下载与配置环境变量 (win 运行 cmd,输入 git 如果出现 git usage 说明则证明配置成功)
  4. Gradle 下载与配置环境变量 (win 运行 cmd,输入 gradle –v 如果出现 gradle 版本说明则证明配置成功)
  5. Tomcat 下载与配置环境变量 (win 运行 cmd,输入 startup 如果启动了 tomcat 窗口就表示配置成功了。启动 Tomcat 后可以在浏览器中输入:localhost:8080)

Jenkins 安装配置

  1. https://jenkins.io/download/ 下载 war 包,然后放置到 tomcat 安装目录下(apache-tomcat-9.0.16\webapps) 输入:http://192.168.1.176:8080/jenkins 即可启动 jenkins
  2. 系统管理—插件管理:根据需要安装插件 Gradle plugin、Android Lint Plugin、Email Extension Plugin、Role-based Authorization Strategy、Build Name Setter Plugin、Extended Choice Parameter Plug-In、Build Pipeline Plugin、HTML Publisher plugin、JaCoCo plugin,Git plugin 等插件
  3. 系统管理 - 全局工具配置:JDK,Git,Gradle
  4. 系统管理 - 系统设置:配置 SDK

job 的创建以及配置(buld-1,test-2,deploy-3)

一:用户权限管理

二:创建子节点服务

三:创建 Pipeline 视图

四:build-1 配置

  1. 创建一自由风格的 job:build-1
  2. 参数化构建,此处是将 build-name 参数化,目的便于知道此项目是由谁构建的.
  3. 构建过程
  4. 构建后操作
  5. 自动触发下一 job

五:test-2 配置

  1. 创建一自由风格的 job:test-2
  2. 参数化构建,此处是自由选择测试用例
  3. 构建过程
  4. 构建后操作 六:deploy-3 类似略过

七:构建后的结果
Pipeline 视图:

代码静态监测结果:

testNG report:

共收到 8 条回复 时间 点赞

把要百度的东西也写一下会比较好

不错不错

我当时用户权限和子节点,一直没成功设置。子节点,我设置 windows 和 linux 都没成功。。sigh

#3 楼 @mmwangying 建议 windows 启动方式,设置为 “ launch slave angents via java web start”;若设置为 “let jenkins control this windows slave as a windows server”;需要将防火墙关闭,还需要修改注册表等,挺麻烦的,请参考如下链接 http://blog.sina.com.cn/s/blog_87f0f17e0101iq8a.html

#4 楼 @xiaoli 恩,好的 谢谢

#4 楼 @xiaoli
你好!我刚接触 jenkins,目前构建的时候遇见几个错误,不知道怎么解决,麻烦帮我看一下,拜托了🙏
邮箱 SMTP 服务器我也设置过了。

Building in workspace /Users/Shared/Jenkins/Home/workspace/test
[test] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson7534676130834581849.sh
+ cd /Library/WebServer/Documents
+ open .
LSOpenURLsWithRole() failed with error -10810 for the file /Library/WebServer/Documents.
Build step 'Execute shell' marked build as failure
Sending e-mails to: xxxxx@xxxx.com
ERROR: Could not connect to SMTP host: mail.xxxx.com, port: 465
javax.mail.MessagingException: Could not connect to SMTP host: mail.xxxx.com, port: 465;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at hudson.tasks.MailSender.run(MailSender.java:129)
    at hudson.tasks.Mailer.perform(Mailer.java:170)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
    at hudson.model.Build$BuildExecution.post2(Build.java:185)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:665)
    at hudson.model.Run.execute(Run.java:1745)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
    at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 18 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
    at sun.security.validator.Validator.validate(Validator.java:260)
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
    ... 28 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
    ... 34 more
Finished: FAILURE
仅楼主可见
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册