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 当即构建。