Ant-contrib should fail but doesn't - jenkins

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!

Related

Problem: failed to create task or type stopwatch Cause: The name is undefined

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"
/>

WebSphere and Java 1.8 Upgrade causes java.lang.AssertionError

Recently I upgraded my WAS application to use JDK 1.8 provided by IBM. But when I try to build my application using Ant. I see the error
BUILD FAILED
C:\Workspace\trunk\APPInstallation\build.xml:1132: The following error occurred while executing this line:
java.lang.AssertionError: org.xml.sax.SAXParseException: Failed to read external schema document "jar:file:/C:/IBM/WebSphere/AppServer/plugins/com.ibm.jaxb.tools.jar!/com/ibm/jtc/jax/tools/xjc/reader/xmlschema/bindinfo/xjc.xsd", because "jar" access is not allowed.
Total time: 29 seconds
I Googled a bit about it, and found that i have to create a jaxp.properties file in the jre/lib folder, which I did, with the value:
javax.xml.accessExternalSchema=all
but it still doesn't work. Any help with this would be welcome! This is area of the ant file where the error comes from:
<wsimport wsdl="${build.dir}/src/${wsdl.file}" destdir="build" wsdlLocation="file:/WEB-INF/wsdl/${wsdl.file}" failonerror="true">
<depends dir="${build.dir}/src" includes="*.xsd" />
<produces dir="${lib.dir}" includes="${webservice.name}${webservice.component}WSBeans.jar"/>
</wsimport>
Do nesting any of these inside your wsimport task resolve it?
<xjcarg value="-Djavax.xml.accessExternalSchema=all"/>
<arg value="-Djavax.xml.accessExternalSchema=all"/>
<arg value="-J-Djavax.xml.accessExternalSchema=all"/>

TeamCity deploy to Tomcat with Ant fails

I'm running TeamCity 7 on Ubuntu 12, and I'm trying to deploy a war file to a tomcat server on machine with IP x using Ant.
The thing is - this worked on a different machine with TeamCity 7, and the only thing I've changed is the machine (moved to Ubuntu running on KVM), and the TC version (upgrade).
I've set ANT_HOME to the correct location, and I see the TC is using it in the build log:
... -Dant.home=/usr/share/ant ...
I've added the following jars to my ANT_HOME/lib:
catalina-ant, tomcat-coyote, tomcat-juli, tomcat-util
The build is running on an agent which has the default Ant settings
My ant file looks like this:
<target name="deploy.to.server">
<property name="port" value="${tomcat.port}"/>
<property name="tomcat.manager" value="manager/text"/>
<property name="url" value="http://${tomcat.server}:${port}/${tomcat.manager}"/>
<property name="path" value="/${server.name}"/>
<echo message="Deploying application to ${url}"/>
<antcall target="undeploy.from.tomcat"/>
<sleep seconds="3"/>
<antcall target="deploy.to.tomcat"/>
</target>
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<target name="deploy.to.tomcat" description="Install web application">
<deploy url="${url}" username="${username}" password="${password}"
path="${path}" war="${work.dir}/${path}.war"/>
</target>
<target name="undeploy.from.tomcat" description="Remove web application">
<undeploy url="${url}" username="${username}" password="${password}"
path="${path}"/>
</target>
I've got this in the TC log:
[Step 1/2] Starting: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java -Dagent.home.dir=/home/system/dev/TeamCity/buildDeployAgent -Dagent.name=Deploy Agent -Dagent.ownPort=9091 -Dagent.work.dir=/home/system/dev/TeamCity/buildDeployAgent/work -Dant.home=/usr/share/ant -Dbuild.number=131 -Dbuild.vcs.number.Nutrino_Monitor_sources=588 -Dbuild.vcs.number.Nutrino_build_scripts=590 -Dfile.encoding=ANSI_X3.4-1968 -Dfile.separator=/ -Djava.io.tmpdir=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp -Dos.arch=amd64 -Dos.name=Linux -Dos.version=3.5.0-19-generic -Dpath.separator=: -Dteamcity.agent.cpuBenchmark=684 -Dteamcity.agent.dotnet.agent_url=http://localhost:9091/RPC2 -Dteamcity.agent.dotnet.build_id=45574 -Dteamcity.auth.password=mlTjdmhOxwfxuM6vGfcQPsKg81q29rFU -Dteamcity.auth.userId=TeamCityBuildId=45574 -Dteamcity.build.changedFiles.file=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp/changedFiles7524737972530602224.txt -Dteamcity.build.checkoutDir=/home/system/dev/TeamCity/Builds/DeployNutritionServer -Dteamcity.build.id=45574 -Dteamcity.build.properties.file=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp/teamcity.build3049879068391711216.properties -Dteamcity.build.tempDir=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp -Dteamcity.build.workingDir=/home/system/dev/TeamCity/Builds/DeployNutritionServer -Dteamcity.buildConfName=Deploy to Integration -Dteamcity.buildType.id=bt38 -Dteamcity.configuration.properties.file=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp/teamcity.config301718488736388101.properties -Dteamcity.projectName=Nutrition Builds -Dteamcity.runner.properties.file=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp/teamcity.runner1078243400245029410.properties -Dteamcity.runtime.props.file=/home/system/dev/TeamCity/buildDeployAgent/temp/agentTmp/ant7992360137092769527runtime -Dteamcity.tests.recentlyFailedTests.file=/home/system/dev/TeamCity/buildDeployAgent/temp/buildTmp/testsToRunFirst5600043147441131768.txt -Dteamcity.version=7.1.2 (build 24170) -Dtomcat.server=integration -Duser.country=US -Duser.home=/home/system -Duser.language=en -Duser.name=system -Duser.timezone=Asia/Jerusalem -Dwork.dir=/home/system/dev/TeamCity/Builds/DeployNutritionServer -classpath /usr/share/java/ant-launcher-1.8.2.jar org.apache.tools.ant.launch.Launcher -lib /home/system/dev/TeamCity/buildDeployAgent/plugins/antPlugin/ant-runtime.jar:/home/system/dev/TeamCity/buildDeployAgent/lib/runtime-util.jar -listener jetbrains.buildServer.agent.ant.AgentBuildListener -buildfile /home/system/dev/TeamCity/Builds/DeployNutritionServer/build/deploy.xml deploy.nutrino.server
[15:06:21][Step 1/2] in directory: /home/system/dev/TeamCity/Builds/DeployNutritionServer
[15:06:21][Step 1/2] taskdef
[15:06:21]
[taskdef] taskdef class org.apache.catalina.ant.DeployTask cannot be found
using the classloader AntClassLoader[]
[15:06:21]
[Step 1/2] The following error occurred while executing this line:
/home/system/dev/TeamCity/Builds/DeployNutritionServer/build/tomcat.tasks.xml:9: taskdef class org.apache.catalina.ant.DeployTask cannot be found
using the classloader AntClassLoader[]
[15:06:21][Step 1/2] Process exited with code 1
[15:06:21][Step 1/2] Ant output
[15:06:21][Ant output] Buildfile: /home/system/dev/TeamCity/Builds/DeployNutritionServer/build/deploy.xml
[15:06:21][Ant output]
[15:06:21][Ant output] BUILD FAILED
[15:06:21][Ant output] /home/system/dev/TeamCity/Builds/DeployNutritionServer/build/deploy.xml:8: The following error occurred while executing this line:
[15:06:21][Ant output] /home/system/dev/TeamCity/Builds/DeployNutritionServer/build/tomcat.tasks.xml:9: taskdef class org.apache.catalina.ant.DeployTask cannot be found
[15:06:21][Ant output] using the classloader AntClassLoader[]
[15:06:21][Ant output]
[15:06:21][Ant output] Total time: 0 seconds
[15:06:22][Step 1/2] Step Deploy (Ant) failed
Now, this is extremely weird, as when I run this from the command line it works perfectly:
ant -buildfile deploy.xml -Dtomcat.server= ...
There is no apparent difference between the two - running it from the CL and through the TC agent should both be running Ant from ANT_HOME (usr/share/ant), and loading the libraries in $ANT_HOME/lib.
Any help would be appreciated.
:)
Thanks!
Just answering the question,
Thanks to #timomeinen - adding the catalina-ant.jar to $ANT_HOME/lib did the job.
That means it is not seeing the lib catalina-ant.jar
You can add:
classname="org.apache.catalina.ant.DeployTask"
classpath="C:\Programming\Tomcat\Instances\8080\lib\catalina-ant.jar"
It will solve this reference problem, but I guess you will face similar problems in the future with other libraries, so in the long term you will still need solve the reference problem.

ant delete task gives error

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.

Why does TFS not report errors and warning generated in the MSBuild exec task?

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.

Resources