Build step выполнить команду windows marked build as failure

Asked

Viewed
6k times

Hy everyone!

In Jenkins when i try to build my job I run a batch command before robocopy /mir pathSource pathDest in tn Configue->Build of my job. But when he executes the command, he stops without run the build.xml. So he prints this just after the command batch before stopping :

16:47:25    Ended : Mon Nov 07 16:47:25 2016
16:47:25 
16:47:25 c:\jenkins_slave\workspace\********>exit 1 
16:47:25 Build step 'Execute Windows batch command' marked build as failure
16:47:26 Sending e-mail to: *********** (launcher, owner).
16:47:26 Notifying upstream projects of job completion
16:47:26 Finished: FAILURE

How can I fix this please?

asked Nov 7, 2016 at 16:09

1

Robocopy have different return codes and error levels which indicates the status of the copy. short version — you can exit 0.
Long version — run the following:

Robocopy SOURCE DEST /e /np /R:5 /mt:64 /XD IGNORE

if errorlevel 16 echo ***FATAL ERROR*** & goto endError
if errorlevel 15 echo FAIL MISM XTRA COPY & goto endError
if errorlevel 14 echo FAIL MISM XTRA & goto endError
if errorlevel 13 echo FAIL MISM COPY & goto endError
if errorlevel 12 echo FAIL MISM & goto endError
if errorlevel 11 echo FAIL XTRA COPY & goto endError
if errorlevel 10 echo FAIL XTRA & goto endError
if errorlevel 9 echo FAIL COPY & goto endError
if errorlevel 8 echo FAIL & goto endError
if errorlevel 7 echo MISM XTRA COPY & goto endError
if errorlevel 6 echo MISM XTRA & goto endError
if errorlevel 5 echo MISM COPY & goto endError
if errorlevel 4 echo MISM & goto endError
if errorlevel 3 echo XTRA COPY & goto endSuccess
if errorlevel 2 echo XTRA & goto endSuccess
if errorlevel 1 echo COPY & goto endSuccess
if errorlevel 0 echo –no change– & goto endSuccess

:endSuccess
exit 0
:endError
exit 1

Good luck!

answered Nov 7, 2016 at 17:10

Dvir669's user avatar

Dvir669Dvir669

6,7171 gold badge20 silver badges21 bronze badges

2

The answer is sort of in the post you linked.

the exit code of last command of the Jenkin’s Execute Shell build step is what determines the success/failure of the Build Step

I get that you understand that much, but what makes it come into play is the return code for robocopy which was you last command. While the link is for server 2008 I won’t be surprised if they are OS common.

Value   Description
0       No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped.
1       All files were copied successfully.

If all the files were copied successfully then the return code is 1. Anything other than 0 is reported as a failure by the build step as we have read in the linked question.


I think what you need to do is check the return code of robocopy and change it.

To check it you need to look at a PowerShell automatic variable $?

$?
Contains the execution status of the last operation. It contains
TRUE if the last operation succeeded and FALSE if it failed.

So the last couple of lines could be…

ROBOCOPY "$env:WORKSPACE\ETL\Project Type 0\bin\DEFAULT" "$outputdir" /E /v
If($?){exit 0}

What this should do is take any non zero result from robocopy and force the script to return true. Again, be aware that this would return OK for all return codes. If this is not desirable then you could easily build some logic for certain codes.

I cannot really test this code as I do not have your environment but in theory it should work or at least get you started on where you need to be.

Katalon Community

Loading

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

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

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

if test case relates to opening of browsers it gets failed via 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

<?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

automated-testing.info

Загрузка…

  • testomat.io управление авто тестами
  • Python
  • Реклама
  • Работа
  • Консультации
  • Обучение

  • Bsod windows 7 0x0000001a windows 7
  • Build qt from sources windows
  • Build ios app on windows
  • Bsod windows 10 все ошибки
  • Build python from source on windows