Skip to end of metadata
Go to start of metadata

smoyers

This plugin makes it possible to run Apache Ant code directly from Jenkins-CI.

Plugin Information

View AntExec on the plugin site for more information.

Features

  • Adding build step to execute Ant code
  • Bundled ant-contrib to support ant-contrib tasks (needs to be enable in global config)
  • Easy to write simple Ant build file directly into the build step
  • Ability to write the fully functional Ant build file directly into Jenkins as a build step
  • You can reuse the build file created by the build step
  • Supports multi-line parameters

Some use cases

  • To do some platform independent tasks
  • To do some advanced build preparation steps
  • To write the custom Ant build file maintained by Jenkins
  • To maintain custom Ant build file when you don't have access into the VCS of the current project
  • To write Ant targets that use multi-line text parameters (currently not possible using the core Ant plugin)
  • And much more (wink)

Support for multi-line text parameters

If your job uses text parameters (as opposed to string parameters) and the parameter values contain newline characters, the core ant plugin fails with the following syntax error:

  Building in workspace c:\svn\automation\baf
  baf $ cmd.exe /C '"ant.bat "-Dmulti_line_text=This is line 1
  This is line 2
  This is line3" usage && exit %%ERRORLEVEL%%"'
  The syntax of the command is incorrect.
  Build step 'Invoke Ant' marked build as failure
  Finished: FAILURE

The problem is that parameters are passed verbatim to the command line, and if they contain any line breaks, cmd.exe will discard everything after the first line break, inevitably leading to a syntax error. The AntExec plugin gets around this problem by saving the build parameters into a .properties file on the fly and loading this file into the Ant session automatically. This also means that you can no longer verify in the build log the list of parameters that were handed down to Ant. If you need this (presumably for debugging purposes) then check the Keep buildfile check box, which will cause the plugin to retain the build file, as well as the parameter properties file, in the workspace of the plugin.

Changelog

1.11 (2015-08-18)
  • Passing parameters and properties through the generated property file instead of command-line which caused problems (especially on Windows)
  • Changed core dependency from 1.480 to 1.596
  • Updated dependency on "token-macro" plugin (1.10)
  • Dropped compatibility with Java 1.5
1.10 (2013-10-31)
  • Fixed missing job options in command line properties
  • Load environment variables with <property environment="env"/> by default, so they are accessible via ${env.VARIABLE}
1.9 (2013-07-15)
  • Fixing upgrade issue with ant-contrib in version 1.8
  • Build files are now automatically deleted by default so you need to update job configuration if you want to keep them
1.8 (2013-06-28)
  • Remove archive copying of buildfile to job directory
  • Cleanup dependencies in pom.xml
1.7 (2013-06-24)
  • Added option to keep build files for each build step, it's deleted by default now
  • Option for disabling  ant-contrib has been moved to build step configuration
  • Changed dependency to core 1.480
  • Added dependency on "ant" plugin (1.2)
  • Added dependency on "token-macro" plugin (1.7)
1.6 (2012-08-28)
  • Fixing typo in extendedScriptSource
1.5 (2012-06-21)
  • Fixing typo
1.4 (2012-06-20)
  • Fixing build file when extended script source is null
1.3 (2012-06-06)
  • First public release

Screenshots:

Adding new build step

New AntExec build step

New AntExec build step with 1st level of advanced options

New AntExec build step with 2nd level of advanced options

Code Example

Code Validation Example

  • No labels

10 Comments

  1. Hi

    Have you got an example of using the "Extended script source" box?

    I have a default target that depends on other targets so I assumed I would add the other targets in the Extended script source box. However, as the "Script source" box seems to expect only an ANT task, I don't seem to be able to make the link using something like:

    <target name="blah" depends="<something in the extended bit>">

    So, let's say I had a build.xml that was something like:

    =========

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="MyCVSCheckout" default="everything" basedir=".">
      <property file="build.properties" />

      <target name="init" description="Remove the previous checkout if it exists.">
        <delete dir="${cvs.module}" />
      </target>

      <target name="checkout" depends="init" description="Do a CVS checkout of the software">
        <cvs failonerror="true">
             <commandline>
               <argument value="-d"/>
               <argument value="${cvs.root}"/>
               <argument value="checkout"/>
               <argument value="-P"/>
               <argument value="-N"/>
               <argument value="-r"/>
               <argument value="${cvs.tag}"/>
               <argument value="${cvs.module}"/>
             </commandline>
        </cvs>
      </target>

      <target name="everything" depends="checkout" description="Do complete checkout"/>

    </project>

    =========

    I've assumed I put the cvs task into the "Script source" box and the "init" target into the "Extended script source" box but the plugin generates the "target" tag round the CVS task with no dependency on the "init" target.

    Can you help?

    Thanks

    John

    1. Hi John, 

      You can't define default target yourself, because the default target is always defined by the "Script source" (first textarea).

      Everything else can be written in the "Extended script source". This is only one rule. It is because in most cases is enough to write the code in one target.

      Milos.

  2. I've just installed the plugin and upon selecting Execute Ant from the drop-down I see this error:
    Could you advise as to where I'd find this class and which JVM it would be needed in?

    Thanks.

    1. Hi Brad,

      I have exactly the same issue, do you find a way to resolve that problem ?

    2. Hi,

      What is your configuration (JRE/JDK/Tomcat/Jety/etc)?

      It shouldn't be fatal it's just the parser of XML in the text-area. You should be able to edit an save code.

  3. R F

    I installed latest Jenkins 1.598 on Windows 7. Under, manage Jenkins: I have IBM JDK set I have ant: org.apache.ant_1.7.1.v20100518-1145 set as ant home I have Jenkins AntExec plug in installed. I created a basic job and tried this code: <echo> java home = $

    Unknown macro: {JAVA_HOME}

    </echo>

    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    <project name="Test">

    <description> Sample bulid file </description>
    <target name="first">
    <echo message="The first five letters of the alphabet are:"/>
    <antcontrib:for list="a,b,c,d,e" param="letter">
    <sequential>
    <echo>Letter @

    Unknown macro: {letter}

    </echo>
    </sequential>
    </antcontrib:for>
    </target>
    </project>

    but I get error:

    antexec_build.xml:
    [echo] java home = C:\Users\xxx\Downloads\eclipseDevelopmentPackage\ibm_sdk71

    BUILD FAILED
    C:\Program Files (x86)\Jenkins\jobs\xxxxx\workspace\antexec_build.xml:12: Problem: failed to create task or type project
    Cause: The name is undefined.
    Action: Check the spelling.
    Action: Check that any custom tasks/types have been declared.
    Action: Check that any <presetdef>/<macrodef> declarations have taken place.
    Any ideas?

    1. Hi,

      Tag <project> is already defined by plugin.

      You can see generated build file by checking "Keep build file" in advanced options of build step.

  4. Hello,

    I am trying to add the following ant command <ivy:retrieve pattern="$

    Unknown macro: {ivy.lib.dir}

    /[artifact]-[revision].[ext]" /> into the textfield Script Source, but I am getting the following error:"antexec_build.xml:9: The prefix "ivy" for element "ivy:retrieve" is not bound."

    Basically I need to add the prefix in the project tag element, but I do not know how can I add it?

    Thanks in advance.

    1. Hi,

      You should be able to use Ivy tasks, but you'll need to define them through the "taskdef" as mentioned in Ivy documentation

  5. Hi Milos,

    Thanks, you gave me an idea and it works.

    Regards.