Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Robot Framework Script return successfully from the shell with "exit 0"

When using Jenkin plugin for Robot Framework, the instruction stated that we need to force robot framework script return successfully from the shell with "exit 0". This is not a very clear statement.

Can someone tell me how we force the robot framework to return with "exit 0" when tests are successful? An example will be very helpful.

Here is the statement in the Jenkins wiki.

Force your Robot script to return successfully from shell with "exit 0" to empower the plugin in deciding if the build is success/failure (by default Robot exits with error code when there are any failed tests)

like image 768
Selenium Master Avatar asked Aug 07 '14 15:08

Selenium Master


1 Answers

In order to tell if a job succeeded or failed, jenkins uses the exit code of the last command that was run. "exiting 0" means to have whatever script runs your test finish with an exit code of 0 (zero).

There are two ways to "exit 0" when robot completes with a failed test:

  1. Explicitly call the exit in the script that runs your tests.
  2. Use the pybot option --nostatusrc

More information about robot framework return codes is covered in the Return Codes section of the robot framework user guide.

Using the exit command

exit is a command you can put into a script to force a specific status code. This command behaves the same both on unix and non-unix systems. It takes one argument (such as 0) and exits the enclosing script with the given value as the exit code.

When you configure jenkins, you are creating a batch script (window) or shell script (non-windows) that contains one or more commands. You can add exit 0 as the last command to force this script to "exit 0".

For example, you can configure your jenkins job to look like this:

pybot mytests.robot
exit 0

In this case, that last line will tell jenkins that the script exited cleanly without errors. The robot plugin for jenkins will then look at the output file (output.xml) to determine whether the build succeeded or failed.

Using the command line option --nostatusrc

Beginning with robot version 2.5.7 you can use the command line option --nostatusrc, which causes robot to always "exit 0" no matter how many tests failed. You can include this option in your jenkins job like so:

pybot --nostatusrc mytests.robot
like image 171
Bryan Oakley Avatar answered Oct 03 '22 01:10

Bryan Oakley