Ask your Symfony questions! Pay money and get answers fast! (more info)

How do I get the exit status of a task called at command line? Symfony


Not really a Symfony question, but I am dealing with this with both Symfony tasks and also other PHP scripts that are called via the command line.

Here is the problem: these scripts are being called from [[LINK href=""]]Jenkins[[/LINK]]

Jenkins assumes a script was successful if its exit status was zero. A PHP script that returns nothing is the same as a script that returns zero. So some failing scripts are being treated successes in Jenkins. I need to return "1" so we can trigger Jenkins automated responses for failures.

I changed the scripts to they "return 1" whenever they fail (wrapped in try{}catch{} blocks, I return 1 from the catch blocks).

From Jenkins, we call the script like this:

sudo su - www-data -c "cd /usr/wonderful/ && /usr/bin/php events_feed_to_scripts_server.lawrence.php"

I am unable to get Jenkins to see that the inner script is returning "1". Any thoughts about how to re-organize this?

Answers (3)


Milena Dimitrova answers:

This should be enough to produce output '1':

echo 1;

You can remove "return 1" from the catch blocks, just use echo and exit.

You can also remove the parentheses after exit if you wish and use it as a language construct.


Joshua Estes answers:


Luis Cordova answers:

> echo $

or something