Common
- 測試驅動開發(Test-driven development,TDD)
- 單元測試、整合測試交由Jenkins定期執行
- 自動部署
 
- 持續整合 Continuous Intgration,CI
- 持續發布 Continuous Delivery,CD
執行流程
- SVN (SCM) → Jenkins → maven (Build Tool) → Tomcat
SVN
- 撰寫的程式碼
- 程式所需資源
- jar
- 設定檔, xml, pom
- 圖片
- javascript, html, css…
 
- 專案結構的配置
- 以不更動既有的資料夾為原則
- 只新增pom
- 缺點:一個結構底下只能存在一個專案
 
Jenkins
- Manage Jenkins
- Global Tool Configuration
- Manage Plugins
- Maven Integration plugin
- Deploy to container Plugin
 
 
- Configure System → Jenkins Location
- New Item
- Source Code Management 版控工具
- Build Triggers
- 觸發時機
- Build periodically 定時任務
- Poll SCM 檢查程式碼是否變更
 
- Schedule,例如:5分鐘 H/5 * * * *
 
maven
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  
  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>...</packaging>
  <dependencies>...</dependencies>
  <parent>...</parent>  
  <modules>...</modules>
  <properties>...</properties> 
 
  
  <build>...</build>
  
  
  <repositories>...</repositories>
</project>
- 使用local jar
- deprecated
- 官方建議:按照規則建置local repository
- groupId: artifactId: version
- 一個組織(group) 可能存在多個Project(atrifact)
 
- 舉例:../javax/servlet/servlet-api/1.0/servlet-api-1.0.jar
 
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/servlet-api.jar</systemPath>
</dependency>
- maven本地存放位置
- local repository:.m2
- workspace
 
- 既有變數
- 根目錄:${basedir}
- deprecated
- 改用${project.basedir}
 
 
- build → plugins
- build-helper-maven-plugin
- maven-compiler-plugin
- maven-war-plugin
 
- outputDirectory
Tomcat
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    ...
</Host>
Result
方向
- pipeline、降低耦合度、減少系統相依性
- 確保 CD 系統能夠被很快地複製

延伸閱讀
Reference 參考資料
- [自動建置實戰]Jenkins+Github+Docker
- https://www.appcoda.com.tw/continuous-delivery/
- [ DevOps ] Jenkins 基本設定及 Pipeline 腳本教學
- jenkins入門
- https://www.techgrow.cn/posts/bd0f3a17.html
 
 
沒有留言:
張貼留言