Tomcat、Jenkins配置

Tomcat、Jenkins配置

安裝Tomcat

下載地址: http://tomcat.apache.org/

啓動

  • 添加管理員帳號

apache-tomcat-9.0.21/conf目錄下修改tomcat-users.xml文件,末尾添加java

<role rolename="manager-gui"/>
 <user username="admin" password="admin" roles="manager-gui"/>
  • 啓動、中止服務器

apache-tomcat-9.0.21/bin目錄下git

啓動: ./startup.sh 
中止  ./shutdown.sh
  • 訪問Tomcat服務器
http://localhost:8080/

Tomcat配置Jenkins

  • 下載Jenkins
https://jenkins.io/,下載jenkins.war文件,
放到 apache-tomcat-9.0.21/webapps 目錄下
  • 配置Jenkins
訪問Jenkins地址:http://localhost:8080/jenkins/
  • Jenkin安裝maven、Git插件

Manage Jenkins-Global Tool Configuration-Maven-安裝Maven,不要在線安裝,很慢。 https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/ 下載maven到本地,而後設置maven_homeweb

Git ,設置本地git 文件地址apache

POM.xml添加插件

pom.xml須要安裝maven的編譯插件和單元測試插件tomcat

//依賴的文件
 <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.13.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.codeborne/phantomjsdriver -->
        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.4.4</version>
        </dependency>

    </dependencies>

<build>
        <plugins>
            <plugin>	//編譯插件
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>	//單元測試插件
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <suiteXmlFiles>
                    //suiteXmlFile是要執行測試的xml,可配置多個
                        <suiteXmlFile>testng1.xml</suiteXmlFile>                        							<suiteXmlFile>testng2.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

        </plugins>
    </build>

jenkins構建項目

Manage Jenkins-Manage Plugins,安裝 Maven Integration plugin,重啓jenkins.服務器

  • 一、新建item-構建一個maven項目,輸入項目名稱。
  • 二、源碼管理,勾選git,輸入Git項目地址
  • 三、Build,Root POM 輸入項目的pom.xml地址,"./pom.xml"表示在根目錄下。
  • 保存,Build NOW 當即構建。
相關文章
相關標籤/搜索