I want delete a directory only if exists.
<target name="clean">
<delete dir="${COMP_BUILD}" />
</target>
this gets error
clean:
[delete] Deleting directory U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\ENT_APP\ESW\bgc-esw-services\build
BUILD FAILED
U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\BUILD\ESW\ESWBUILD\build.xml:451: The following error occurred while executing this line:
U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\ENT_APP\ESW\bgc-esw-web\build.xml:207: The following error occurred while executing this line:
U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\ENT_APP\ESW\bgc-esw-web\build.xml:84: The following error occurred while executing this line:
U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\ENT_APP\ESW\bgc-esw-services\build.xml:64: Unable to delete directory U:\id824275_03_2011_06_JUN_ESW\CCS_WSC_ECM\ecm_esw\app\ENT_APP\ESW\bgc-esw-services\build\lib
You could specify failonerror:
<delete dir="${COMP_BUILD}" failonerror="false"/>
This will continue execution if the directory doesn't exist.
The trouble with this is that if the directory does exist, but can't be deleted for some other reason, then it will also still carry on.
Related
BUILD FAILED
E:\Tasks\Task - 2 (ant dd)\Testing\build.xml:50: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\checks.xml:123: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\accountsurlcheck.xml:21: The following error occurred while executing this line:
E:\Tasks\Task - 2 (ant dd)\Testing\accountsurlcheck.xml:54: Problem: failed to create task or type stopwatch
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
Im getting this eror when I run ant .
I have copied ant-contrib-0.5.jar to the lib of ant installed directory and also added <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> to my build.xml.
line 54 of accountsurlcheck.xml :
<stopwatch name="total_time" action="start"/>
Line 21 :
<antcall target="urllist"/>
Your taskdef for ant-contrib is missing a classpath that points to the ant-contrib jar.
<taskdef
classpath="/path/to/ant-contrib.jar"
resource="net/sf/antcontrib/antcontrib.properties"
/>
I'm trying deploy a PHP application using Ant script. I've put all the necessary jars in the library: ie ant-jsch-1.8.1.jar, jsch-0.1.55.jar
In my script i declare the sshexec and scp as followed:
<path id="jsch.class.path">
<pathelement location="lib/ant-jsch-1.8.1.jar" />
<pathelement location="lib/jsch-0.1.55.jar" />
</path>
<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch.class.path" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jsch.class.path" />
When the build is executed in Jenkins i get these errors event though the location of the public key is correct:
[sshexec] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
[sshexec] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
[scp] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
The weird thing is when i run the build script locally on my machine it works fine.
Any help would be much appreciated.
The issue was that I had a variable that holds the path to the private key, the string probably had an extra space or character and ANT got confused. I replaced variable with the direct path of the private key and it worked. To reuse the variable I copied the path and assigned it to the same variable in run command.
I'm trying to deploy several systems with one script containing two targets. When one systems fails to deploy, I want to stop the whole script and fail.
<target name="deploy_all">
<for list="${systems}" param="system" delimiter="," parallel="false" threadCount="1" trim="true">
<sequential>
<antcall target="deploy_one_system">
<param name="system" value="#{system}" />
</antcall>
</sequential>
</for>
</target>
<target name="deploy_one_system">
<trycatch property="error_system">
<try>
<!-- deployment -->
<!-- Deep in other targets, there's <fail> -->
</try>
<catch>
<echo>Error during deployment of ${system}:</echo>
<echo>${error_system}</echo>
<!-- print logs, errors, cleanup -->
<if>
<contains string="${stop_execution_on_fail}" substring="${system}" />
<then>
<echo message="I should fail here!" />
<fail message="Error occured during deploying ${system}."/>
</then>
</if>
</catch>
</trycatch>
</target>
The problem is that the condition is evaluated correctly and message "I should fail here!" gets printed, but the build doesn't fail and continues deploying next system.
Variable ${stop_execution_on_fail} is supplied to the script and contains list of systems which should fail the whole build (instead of deploying the rest of systems).
Sometimes, the build fails after deploying several systems running out of memory.
17:07:03 deploy.xml:900:
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system1.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system2.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system3.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:4: java.lang.OutOfMemoryError: PermGen space
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:4: java.lang.OutOfMemoryError: PermGen space
I'm running Jenkins 1.642.1, JDK 1.8.0_74 and Ant 1.9.2.
Any ideas?
EDIT (based on pczeus' comment): The following is printed (don't mind timestamps, I took it from another build):
10:12:56 [echo] Error during deployment of system1:
10:12:56 [echo] The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:739: The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:647: The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:473: The following error occurred while executing this line:
10:12:56 [echo] dbmaintain.xml:229: Unable to perform db maintain task.
--- omitted ---
10:12:56 [echo] I should fail here!
As you can see, the condition is evaluated successfully, as the message I should fail here! is printed.
stop_execution_on_fail variable contains comma-separated list of systems where to fail:
system1,system2,system3
I believe your issue is within your
<contains string="${stop_execution_on_fail}" substring="${system}" />
You are checking for a substring matching the system in the overall string stop_execution_on_fail. However, your try:
<trycatch property="error_system">
Is setting the error message within the error_system property, which you are not checking in your contains.
Try changing the <contains> to:
<contains string="${error_system}" substring="${system}" />
I traced the error down using Chad Nouis' suggestion and found out the following:
First, I was stupid when I didn't post the actual code but just excerpt and some variables substituted. Shame to me!
The parallel attribute in <for> call in deploy_all target was set to true. In that case, even with threadCount set to 1, Ant does fail the target, but doesn't prevent the for cycle from running next loop (although I'm convinced it should).
Thank you, Chad Nouis!
In one of our build script, we have following simple copy task added ->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
This copy task started hanging when the glassfish jar name got changed (version upgrade which are not in our control) at the source location. I was expecting it to error out causing the build failure in that case. Actually at first I was not able to figure out at what particular step build was hanging. Then when I added "-debug" to the ant command and I realized its successfully completing a step prior to this copy task and still there was no trace of copy command that is hung. When I updated the new jar name, it worked fine and build was successful which proved that the copy task is hanging because of filename got changed. To make it easy to debug next time, I added an echo statement like below just prior to that copy task ->
<echo message="Copying glassfish jar to ${targetdir}.."/>
But I am still confused as to why it didn't give error with build failure? I am using Apache Ant version 1.7.1. Could this be a bug? How else I can avoid this situation in future with just the copy task (without using * in the jar name)? TIA
That worked for me. Well, didn't work for me. I got the error message. I am using Ant 1.8 and Ant 1.9.2. I didn't try it with Ant 1.7, but I doubt it's a bug.
Try to use the -v parameter in Ant:
$ ant -v target
And be prepared for a longwinded output. This will give you information what's going on with Ant, and may explain why it's freezing. There's a few things you could do: Use a fileset to specify the file.
<copy todir="${targetdir}">
<fileset dir="${sourcedir}/modules">
<include name="glassfish*.jar"/> <!-- Will catch any glassfish.jar -->
</fileset>
</copy>
Of course, if the file doesn't exist, you won't get an error or even a warning. However, a <fail/> before will detect the issue:
<fail message="missing file ${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar">
<condition>
<not>
<available
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
type="file"/>
</not>
</condition>
</fail>
To force the build to quit, an alternative way
<available file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
property="glassfish.jaxb.xjc.jar.present"/>
<fail message="you message" unless="glassfish.jaxb.xjc.jar.present"/>
just a few lines less :)
If you want to dig into it, try this:
write a simple build file, which contains only one target with copy, and put it to the same place of your main build file.
<target name="test-copy">
<!-- here use an old (wrong) file name -->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
</target>
run it, check if it fails or hangs.
If this simple build file works, it's very possible that something else in your main build file is causing the bug.
In my TFSBuild.proj I have the following Exec commands:
<Target Name="AfterCompile">
<Exec Command="#echo Program.cs(12,20): warning CS1002: ; missing"/>
<Exec Command="#echo Program.cs(13,20): Warning CS1003: ;; missing"/>
<Exec Command="#echo Program.cs(14,20): error CS1004: ;;; missing"/>
</Target>
The TFS build fails, because it parses the output and sees an error reported in it.
I get the following output in buildlog.txt:
Program.cs(12,20): warning CS1002: ; missing
Program.cs(13,20): warning CS1003: ;; missing
Program.cs(14,20): error CS1004: ;;; missing
c:\bw\10\BuildType\TFSBuild.proj(228,5): error MSB3073: The command "#echo Program.cs(14,20): error CS1004: ;;; missing" exited with code -1.
But I don't get these errors reported in the result details:
While errors and warnings are reported on a normal project build with a link to a file containing the set with found warnings and errors:
Any idea on getting the list of errors and warnings parsed out of the exec output and into the TFS reporting?
Solved my own question as follows:
I created a myexec.proj file that does the execution of the Exec.
In TFSBuild.proj I execute the solution using <SolutionToBuild Include="myexec.proj"/>.
The output is now automatically parsed for errors and warnings.