jenkins------結合maven將svn項目自動部署到tomcat下

  • 下載Jenkins war包,下載地址

  • 配置Tomcat用戶

    • 打開tomcat的conf目錄下的tomcat-users.xml,修改成一下內容

      <?xml version='1.0' encoding='utf-8'?>
      <!--
        Licensed to the Apache Software Foundation (ASF) under one or more
        contributor license agreements.  See the NOTICE file distributed with
        this work for additional information regarding copyright ownership.
        The ASF licenses this file to You under the Apache License, Version 2.0
        (the "License"); you may not use this file except in compliance with
        the License.  You may obtain a copy of the License at
      
            http://www.apache.org/licenses/LICENSE-2.0
      
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
      -->
      <tomcat-users>
      <!--
        NOTE:  By default, no user is included in the "manager-gui" role required
        to operate the "/manager/html" web application.  If you wish to use this app,
        you must define such a user - the username and password are arbitrary.
      -->
      <!--
        NOTE:  The sample user and role entries below are wrapped in a comment
        and thus are ignored when reading this file. Do not forget to remove
        <!.. ..> that surrounds them.
      -->
      <!--
        <role rolename="tomcat"/>
        <role rolename="role1"/>
        <user username="tomcat" password="tomcat" roles="tomcat"/>
        <user username="both" password="tomcat" roles="tomcat,role1"/>
        <user username="role1" password="tomcat" roles="role1"/>
      -->
      <role rolename="admin-gui"/>
      <role rolename="admin-script"/>
      <role rolename="manager-gui"/>
      <role rolename="manager-script"/>
      <role rolename="manager-jmx"/>
      <role rolename="manager-status"/>
      <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
      </tomcat-users>
  • 部署jenkins,將war包放到webapps便可

  • 打開jenkins,http://yourserver/jenkins/(這裏我已經構建了項目)

    • 打開界面

    • 配置jdk和maven路徑,在系統管理->系統配置

      • 配置jdk

      • 配置maven(不配置jvm參數很容易內存溢出)

    • 配置項目參數

      • 配置代碼路徑

      • 設置build參數,有個polling SCM能夠設置定時構建,愛啥時候發佈就是啥時候發佈。用法點旁邊的問號就行,和Quartz的表達式還有點不同。

      • 當即構建

      • 查看日誌輸出若是爲下面的代表構建成功
  • 項目的pom文件添加Tomcat插件

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <!-- 配置項目自動發佈服務器 -->
            <path>/${project.build.finalName}</path>
            <update>true</update>
            <url>http://yourIp:yourPort/manager/text</url>
            <server>tomcat</server>
            <warFile>${basedir}/target/${project.build.finalName}.war</warFile>
            <uriEncoding>UTF-8</uriEncoding>
            <charset>UTF-8</charset>
        </configuration>
    </plugin>
相關文章
相關標籤/搜索