jenkins自動打包並發布到測試環境


一 步驟

  1. maven中加入cargo插件
  2. Tomcat中增加相應管理員用戶
  3. 在POM中加入cargo參數配置,配置tomcat相關信息、部署的包名、部署路徑
  4. jenkins配置job信息,源碼管理、構建觸發器、構建動作-執行的maven命令
  5. jenkins配置job信息,構建后動作-自動發布插件配置,該中間件信息為測試環境相關

二 說明

  1. maven中加入cargo插件
      <pluginGroups>
        <!-- pluginGroup
         | Specifies a further group identifier to use for plugin lookup.
        <pluginGroup>com.your.plugins</pluginGroup>
        -->
        <pluginGroup>org.codehaus.cargo</pluginGroup>
      </pluginGroups>

     

  2. Tomcat中增加管理員用戶

    <role rolename="tomcat"/>
    <role rolename="role1"/>
    <role rolename="manager-script"/>
    <role rolename="manager-status"/>
    <user username="tomcat" password="tomcat" roles="tomcat"/>
    <user username="both" password="tomcat" roles="tomcat,role1"/>
    <user username="role1" password="tomcat" roles="role1"/>
    <user username="admin_ci" password="admin_ci" roles="manager-gui,manager-script,manager-status"/>

  3. 在POM中加入cargo插件
    <plugin>
                  <groupId>org.codehaus.cargo</groupId>
                  <artifactId>cargo-maven2-plugin</artifactId>
                    <version>1.2.3</version>
                    <configuration>
                        <container>
                              <!-- 指明使用的tomcat服務器版本 -->
                            <containerId>tomcat8x</containerId>
                            <type>remote</type>
                        </container>
                        <configuration>
                            <type>runtime</type> 
                            <cargo.remote.username>admin_ci</cargo.remote.username> 
                            <cargo.remote.password>admin_ci</cargo.remote.password> 
                            <cargo.tomcat.manager.url>http://127.0.0.1:8081/manager</cargo.tomcat.manager.url> 
                        </configuration>
                    </configuration>
                    <executions>  
                      <execution>  
                          <phase>deploy</phase>  
                          <goals>  
                              <goal>redeploy</goal>  
                          </goals>  
                      </execution>  
                  </executions>
             </plugin>      

     

  4. 配置jenkins

       在jenkins中安裝Deploy Plugin、在jenkins服務器中配置maven環境

   創建maven風格job

   配置源碼管理信息

   build觸發規則

   Pre Steps設置:Goals  clean install -Dmaven.test.skip=true

   Build配置:Root POM-pom文件名,一般為pom.xml、Goals and options-celan install

   構建設置-Post-build Actions:添加步驟 Deploy war/ear to a container

      WAR/EAR files:target/war包名稱.war

      Context path:空

      Containers:  

        選擇容器類型

        Credentials:創建中間件登陸用戶和密碼

        Tomcat URL:輸入tomcat訪問地址,如http://127.0.0.1:8081

 

最后進行構建測試。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM