If I have a set of commands in a <target> in my build.xml file, is there a way to stop ant from executing the next command if the previous one returned an exit code of -1? Is it standard ant behavior to exit when a command fails or to keep going despite a bad exit code?
<exec> task has failonerror to make the task to stop the build when the external command exits with an return code indicating error.
It also has resultproperty to save the return code to a property so that you can do more conditional checking later. However, it's only of interest when failonerror isn't set to true.
See <exec> task's manual: http://ant.apache.org/manual/Tasks/exec.html
When you set failonerror="true", the only possible value for resultproperty is 0. Any non-zero response is treated as an error and would mean the build exits.
Related
I'm relatively new to using build files and Ant to compile and execute from a command line so i wanted to know how it would be possible to modify the build-impl.xml file auto generated from netbeans so that after it compiles it also executes the program.
Currently when i type just "ant" in the command window where the build.xml file is listed it compiles and etc but then says
-do-jar-copylibs:
[copylibs] Nothing to copy.
[echo] To run this application from the command line without Ant, try:
[echo] java -jar "C:\Users\Eric\Documents\Word Documents\Java Test Code\NetbeansVersion\Cops\dist\Cops.jar"
I can run that command and it will run fine, but i want the program to execute by just typing ant.
The build.xml file - Pastebin
Build-impl.xml file - Pastebin
There are a couple "tasks" available in ant that you could use to accomplish this.
You can use either of these:
Java Task,
Exec Task
Those documentation pages provide examples as well. Before you go there though, you might want to start at the basic manual to get an idea of the structure of an ant build file to determine where and how you want to add this execution step in.
It feels a little "off" to me to have your build script executing the program, but I'm sure you've got a reason, so I might suggest adding a new target that does the build steps and then also runs this command to kick off the program. That way you've still got the option of running the build without running the program.
How to save current process running time in some text file using Ant, then read file and assign to Ant variable?
You can use ant exec task. There you can specify the executable ps and the necessary arguments (PID, options). You can check the argumengs here.
You specify outputproperty in ant exec task so the output will be redirected to this property.
Then you can put the value in a file using the echo task.
Robot framework is generic keywords base testing framework. So can we use Ant task as a keyword in robot?
If yes what are the possible ways?
You can't use directly a Ant Task as a Robot keyword, but you can use Run Process keyword from the Process Library to launch the Ant command line you want to run:
*** test cases ***
my test
Run Process ant command line to launch
We can use "Run And Return Rc And Output" keyword from "OperatingSystem" Library
*** test cases ***
Test Ant
${RC} ${Output} Run And Return Rc And Output ant -f "antFile name"
where you need to set ANT_HOME and also set ANT in path variable
as
set PATH=%PATH%;%ANT_HOME%/bin
which will then run the ant task defined in ant file.
#{Flag}= Run And Return Rc And Output run.py
should Contain #{Flag} Camera Locked
The result will be saved in Flag variable and the next line will search for Camera Locked Text in output.
If you simply want to run just use Run And Return Rc
I invoke our gtest suite for iOS in Jenkins using the shell script
#!/bin/sh
pkill -a "iPhone Simulator"
ios-sim launch ${WORKSPACE}/source/apple/build/Debug-iphonesimulator/MyAppTest.app --args --gtest_output=xml:${WORKSPACE}/JUnitTestResultsIOS.xml
exit $?
This always successfully runs the tests, and when the tests pass the xml file gets generated as expected. However, when the tests fail, no xml file is generated, and the "Execute shell command" build step terminates but does not fail the job. I echoed the exit code and it comes back 0 even when the tests fail.
This is even more confusing to me since we have a basically identical script in the same job for running tests on our OSX version. This always writes the xml and successfully fails the job when the tests fail.
This behavior seems totally arbitrary and everything about our configuration seems to be exactly as it should be. What am I missing?
Thanks!
There were two things at work here.
First of all, we had the break_on_failure gtest option enabled, which works great when running tests on a local machine but isn't useful within Jenkins, so we disabled it on the build machine.
The second issue was around how we used the exit code. Since ios-sim launch ... always succeeds we were always getting an exit code of 0, regardless of whether the tests passed or failed. I ended up using grep to determine if the resulting xml file indicated any failures, and generated an exit code based on that.
Following is the bat script code block on which i am working on:
ECHO off
IF NOT EXIST "%ANT_HOME%" (
SET ANT_HOME=%~dp0%build\apache-ant-1.8.2
SET ANT_BIN=%~dp0%build\apache-ant-1.8.2\bin
SET PATH | FIND "%ANT_HOME%;%ANT_BIN%"
)
cd "build\Run"
ant -q
cd ../..
echo "Program Terminated!"
exit
Now, my build.xml file is inside this build\Run folder so that i am first navigating to build/Run before running ant -q command (NOTE: I don't want to change this method of navigating).
The moment ant -q command is executed following things happen:
Set the environment variables as the condition.
Change directory to build\Run.
As my build.xml is inside the Run directory the ant -q command run correctly.
Ant executed correctly and not ant script terminates.
Now my current path will be build\Run ! correct <= Here i don't want this after ant is terminated, instead i want to come out from build\Run that's why i used cd../..
But the problem is I am not able to execute the commands after ant -q. This happens be the program control goes from BATCH => ANT.
Is there any way to execute my command after ant command from bat script itself ?
You may find that the ant being run is a batch file itself, in which case it simply chains to it (no return).
You should try this instead:
call ant -q
Calling a batch file (as opposed to chaining) will correctly return to the point after which you called it.