首页 > 解决方案 > jenkins 与 maven 问题的集成

问题描述

从 jenkins 执行代码时遇到 PluginResolutionException。当我从 eclipse 执行相同的代码时,它可以工作,但它在 jenkins 中不起作用。它向我显示了 pluginResolutionexception。

public class LoginPageTest extends TestBase {

LoginPage loginpage;
EnquiryPage enquirypage;
HomePage homepage;

public ExcelToDataProvider dataproviderclass = new ExcelToDataProvider();
String xlfilepath = "E:\\ExcelData.xlsx";
String sheetname = "Sheet1";
WaitHelper waithelper;
static Logger logger = Logger.getLogger(LoginPageTest.class);

public LoginPageTest() {
    super();
}

@BeforeTest
public void setUp1() {
    initialization();
    loginpage = new LoginPage();
    enquirypage = new EnquiryPage();
    waithelper = new WaitHelper(driver);

    PropertyConfigurator.configure(System.getProperty("user.dir") + "\\"+XpathClass.log4jProp);
}

@Test(dataProvider = "userData", dataProviderClass = ExcelToDataProvider.class)
public void loginMethod(String username, String password) throws InterruptedException {

    homepage = loginpage.login(username, password);
    logger.info("login method executed");

}

@Test(dataProvider = "enquiryData", dataProviderClass = ExcelToDataProvider.class, dependsOnMethods = {"loginMethod"})
public void addEnquiry_validDetails(String name, String phNum, String emailId, String gender, String birthday, String birthMonth, String birthYr, String country, String sourceName, String institutename, String standard, String sub1, String sub2, String masterCourse, String course1, String course2, String enquiryPriority, String followuptype, String walkinDay, String walkinmonth, String walkinyr,String refferedName, String branch, String assignto,String comments )
        throws Exception {
    logger.info("*********************************************************************");
    enquirypage.add_Enquiry();
    enquirypage.stud_information(name,phNum,emailId,gender,birthday, birthMonth,birthYr, country, sourceName,institutename,standard, sub1, sub2,masterCourse,course1, course2,enquiryPriority,followuptype, walkinDay,  walkinmonth,  walkinyr, refferedName,  branch,  assignto, comments);


}
   }

这是 testng.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="5" name="Test">
    <classes>
      <class name="testScripts.LoginPageTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

这是我的 POM.xml 文件。我已经在 jenkins 中链接了这个 pom.xml 文件路径。仍然显示错误

        <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>project</groupId>
    <artifactId>proctur</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>proctur</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <!-- <scope>test</scope> -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.0-beta</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.12.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.12.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.16</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.16</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>


    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>

                <!-- <configuration> <mainClass>testScripts.LoginPageTest</mainClass> 
                    </configuration> -->
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>

                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>


            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>testScripts.LoginPageTest</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <!-- <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> 
                <configuration> <source>1.8</source> <target>1.8</target> <fork>true</fork> 
                <executable>C:\Program Files\Java\jdk1.8.0_212\bin\javac.exe</executable> 
                </configuration> </plugin> -->

        </plugins>
    </build>
</project>


FailedConsole Output
Started by user ashwini
Running as SYSTEM
Building in workspace C:\Users\Proctur\.jenkins\workspace\Proctur_AutomationProject
Parsing POMs
Established TCP socket on 61274
[proctur] $ "C:\Program Files\Java\jdk1.8.0_212/bin/java" -cp C:\Users\Proctur\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-agent-1.13.jar;C:\Users\Proctur\.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven\boot\plexus-classworlds-2.6.0.jar;C:\Users\Proctur\.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven/conf/logging jenkins.maven3.agent.Maven35Main C:\Users\Proctur\.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven C:\Users\Proctur\.jenkins\war\WEB-INF\lib\remoting-3.29.jar C:\Users\Proctur\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven35-interceptor-1.13.jar C:\Users\Proctur\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.13.jar 61274
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f E:\New folder\proctur\pom.xml compile test
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< project:proctur >---------------------------
[INFO] Building proctur 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.20.1/maven-surefire-plugin-2.20.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12.667 s
[INFO] Finished at: 2019-09-16T16:05:37+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-surefire-plugin:2.20.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-surefire-plugin:jar:2.20.1: Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.20.1 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: Unknown host repo.maven.apache.org -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
[JENKINS] Archiving E:\New folder\proctur\pom.xml to project/proctur/0.0.1-SNAPSHOT/proctur-0.0.1-SNAPSHOT.pom
channel stopped
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/*.xml
Did not find any matching files.
Finished: FAILURE

标签: javamavenseleniumjenkinstestng

解决方案


您的具体问题可能是由各种原因引起的。

您是否在与 Eclipse 实例相同的机器上运行 Jenkins?

实际错误表示为:

[错误] 插件 org.apache.maven.plugins:maven-surefire-plugin:2.20.1 或其依赖项之一无法解析:无法读取 org.apache.maven.plugins:maven-surefire-plugin 的工件描述符:jar:2.20.1: 无法从/到中央传输工件 org.apache.maven.plugins:maven-surefire-plugin:pom:2.20.1 ( https://repo.maven.apache.org/maven2 ): repo.maven.apache.org:未知主机 repo.maven.apache.org -> [帮助 1]

注意:未知主机 repo.maven.apache.org

Jenkins 正在运行的机器无法访问 repo(可能需要代理,或者主机条目不正确等)

或者您在 Jenkins 本身上设置了不正确的代理,请开始查看您在 Jenkins 中的配置。


推荐阅读