views:

51

answers:

3

I have some code I run against other code. Let say command x runs code blah.c

I have written a script to check to see if that command executed successfully. I am able to determine this. I will be running the script in the execute build box available in hudson.

I need to know who to fail the build if any of there code tests fail. meaning command x ran on blah.c returned in failure.

Best practices for jobs not built by maven. Is it possible to integrate maven?

Please and thank you.

+1  A: 

Personally, I use either ANT or Phing for this kind of thing. You can specify the steps necessary to complete a "target".

So in your case, you'd specify an exec task. Then, you'd set the checkreturn property on that task. So that way, if the command returns anything but 0, it'll fail the target. And Hudson will automatically fail the build.

The nice thing about this, is that you can manually execute the ANT build task outside of Hudson (so you don't need to commit to verify if it will build successfully). I personally keep my phing build.xml file inside the same version control as my project so that I always have it available...

ircmaxell
where would i do this? could you please give an example. :)
garbagecollector
There are a bunch of resources on it. Here are a few: [Hudson Tutorial](http://www.vogella.de/articles/ContinuousIntegration/article.html), [A CI Tutorial](http://www.ibm.com/developerworks/java/tutorials/j-cq11207/), [An Ant Tutorial](http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html), [Another Ant Tutorial](http://i-proving.ca/space/Technologies/Ant+Tutorial)...
ircmaxell
@ircmaxell I was talking about the `exec` command and the `checkreturn`. I am familiar with hudson.
garbagecollector
Those are part of both [ANT](http://ant.apache.org/manual/Tasks/exec.html) and [Phing (](http://phing.info/docs/guide/current/chapters/appendixes/AppendixB-CoreTasks.html#ExecTask) Since Phing is really just a re-implementation of ANT)... As for how to do it in Hudson, how are you running the command (through the XShell plugin by any chance)?
ircmaxell
I am running the script from execute shell under build. I just need to be able to fail the build from a script if something happens within that script to simplify my problem.
garbagecollector
The help subpart of the `Execute Shell` part in project config says this: `By default, the shell will be invoked with the "-ex" option. So all of the commands are printed before being executed, and the build is considered a failure if any of the commands exits with a non-zero exit code. Again, add the #!/bin/... line to change this behavior.`
ircmaxell
@ircmaxell thanks for your persistence :)
garbagecollector
If you wish, you can also incorporate ant tasks into your maven config using [maven-antrun-plugin](http://maven.apache.org/plugins/maven-antrun-plugin/index.html). I only mention this as the OP hints at maven integration.
puug
+1  A: 

If you're running a shell script, you can indicate failure by exiting with a non-zero error code.

run_my_command foo
if [ $? -ne 0 ]; then
    echo "run_my_command failed"
    exit 1
fi

I agree with @ircmaxell that there are better ways to write build scripts than writing shell scripts directly in Hudson.

Dave Bacher
A: 

Yes, you can use the M2 Extra Steps plugin for hudson in order to issue shell commands prior/after your maven build, with conditional control (eg, if this command fails, skip running Maven, aborting the build)

We use that in order to cleanup some stuff prior to running the build.

aldrinleal