java 构建步骤“执行 Windows 批处理命令”将构建标记为失败完成:失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34476561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:55:51  来源:igfitidea点击:

Build step 'Execute Windows batch command' marked build as failure Finished: FAILURE

javajenkins

提问by Hassan

I've configured my project to run the Build with Jenkins if I execute the testng.xml on my own it successfully execute my test case but if I execute via Jenkins I get the following error message

我已经将我的项目配置为使用 Jenkins 运行构建,如果我自己执行 testng.xml,它会成功执行我的测试用例,但是如果我通过 Jenkins 执行,我会收到以下错误消息

Build step 'Execute Windows batch command' marked build as failure Finished: FAILURE

构建步骤“执行 Windows 批处理命令”将构建标记为失败完成:失败

However it execute the build successfully if test case output is just using `(system.out.println();)

但是,如果测试用例输出只是使用`(system.out.println();),它会成功执行构建

if test case relates to opening of browsers it gets failed via Jenkins

如果测试用例与打开浏览器有关,它会通过 Jenkins 失败

This is my test class

这是我的测试课

    public WebDriver driver;
    public String baseUrl = "http://iparkit.com/";

    @BeforeMethod
      public void initializeWebDriver() {

          driver = new FirefoxDriver();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
          driver.get(baseUrl);
          driver.manage().window().maximize();
      }
    //Close Browser after each test case execution
    @AfterMethod
    public void closeBrowser()
    {
        driver.close();
    }
    @Test(enabled=true) //TC2-01 - OK
    public void iparkit_valid_email_password() throws InterruptedException
    {
        driver.findElement(By.xpath(".//*[@id='mast']/nav/ul/li[4]/a")).click();
        driver.findElement(By.xpath(".//*[@id='email']")).sendKeys("[email protected]");
        driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("*******");
        driver.findElement(By.xpath(".//*[@id='top']/div/main/form/main/fieldset[3]/button")).click();
        String Expectedlnktext = driver.findElement(By.linkText("Sign Out")).getText();
        String Actuallnktext = "Sign Out";
        Assert.assertEquals(Actuallnktext,Expectedlnktext);
    }
}

and here is my testng.xml

这是我的 testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test">
    <classes>
       <class name="automationframework.Iparkittesting"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

here is last console output

这是最后一个控制台输出

Started by user anonymous
Building in workspace D:\K - Selenium\SeleniumWorkspace\iParkit_copy
[iParkit_copy] $ cmd /c call C:\Windows\TEMP\hudson4187523140058494240.bat

D:\K - Selenium\SeleniumWorkspace\iParkit_copy>run.bat

D:\K - Selenium\SeleniumWorkspace\iParkit_copy>java -cp bin;lib/* org.testng.TestNG testng.xml 
[TestNG] Running:
  D:\K - Selenium\SeleniumWorkspace\iParkit_copy\testng.xml


===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

回答by RicoPuerto

Using exit /b 0at the end of the batch script should do the trick.

exit /b 0在批处理脚本的末尾使用应该可以解决问题。

回答by Timmy Brolin

The batch command will examine the "error level" of the last command (return code). Anything but zero will result in failure. You don't give much details, but it seems your browser returns a non-zero error level.

批处理命令将检查最后一个命令(返回代码)的“错误级别”。除了零之外的任何事情都会导致失败。您没有提供太多细节,但您的浏览器似乎返回了非零错误级别。

You could run a dummy command after the browser to chance the error level. Or fix whatever reason is causing the non-zero error level (recommended solution)

您可以在浏览器之后运行一个虚拟命令来确定错误级别。或修复导致非零错误级别的任何原因(推荐解决方案)

Example of a popular dummy command to set the error level is "ver > nul"

设置错误级别的流行虚拟命令示例是“ver > nul”