1

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
trainmaster
  • 145
  • 10
  • 1
    To fix your PermGen space issue: http://stackoverflow.com/questions/6387380/how-to-increase-ant-permgen-size – Bruno Lavit Mar 08 '16 at 17:03
  • @BrunoLavit Thanks, I left it in the error message when I tested running the script with JDK6. JDK8 doesn't print anything, it just gets stucked. – trainmaster Mar 09 '16 at 08:10
  • Try running Ant with the `-logger org.apache.tools.ant.listener.ProfileLogger` option. This will show whether Ant is even entering the `` task after the `` task. Also consider running Ant with the `-debug` option to see if it reveals any issues. – Chad Nouis Mar 10 '16 at 15:50
  • Thank you, it helped me very much! I wasn't aware of the ˛`-logger` switch. – trainmaster Mar 10 '16 at 17:42

2 Answers2

0

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}" />
pczeus
  • 7,709
  • 4
  • 36
  • 51
  • Hello, thank you for your suggestion, but it's not the issue. I added the respective part to the script excerpt in the question, so it shouldn't be confusing now. The condition is evaluated correctly and the echo message within the block is printed. – trainmaster Mar 09 '16 at 08:16
  • Can you show us what the 2 `` statements print out for system and erorr_system? Can you also add an echo for stop_execution_on_fail and provide that? The only thing that makes sense is the comparison is failing. – pczeus Mar 10 '16 at 02:41
  • I added it to the question. – trainmaster Mar 10 '16 at 07:41
  • I actually thought the condition is the root cause.But it was disproved by added the "I should fail here" echo. – trainmaster Mar 10 '16 at 07:47
0

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!

Community
  • 1
  • 1
trainmaster
  • 145
  • 10