Integrating the Rational Application Developer ANT build scripts in Rational Team Concert

Technote (FAQ)


Question

How do you propagate build errors reported by an IBM Rational Application Developer (RAD) ANT build script to IBM Rational Team Concert (RTC)?

Cause

If you execute a Rational Application Developer ANT build script where build errors are reported, these errors are not shown in the Rational Team Concert Build Results view.

Answer

The set of steps below describes how to ensure that build errors reported by a Rational Application Developer ANT build script are also visible in the build results editor in Rational Team Concert.

The sample ANT script includes tasks from three sources: Rational Application Developer, Rational Team Concert Build Toolkit and Ant-Contrib. (See the Related information section for the download location of Ant-Contrib.)

The script uses the following Rational Application Developer tasks: workspaceBuild and projectImport.

The script uses the following Rational Team Concert tasks: startBuildActivity, completeBuildActivity and logPublisher.

The script uses the following Ant-Contrib tasks: if, then, else.


Prerequisites:

  1. Install Rational Team Concert server 3.0.1.3

  2. Install Rational Team Concert Build Engine 3.0.1.3

  3. Install Rational Application Developer 8.0.4

  4. Install Rational Team Concert Client Extension for Eclipse IDE 3.0.1.3 in the same package group as Rational Application Developer. Note that if you are using a 64 bit Package Group for Rational Application Developer, you need to use at least Rational Team Concert 3.0.1.1 (See Related URL for more information).

  5. Start the Jazz Build Engine (JBE) with a command like the following:

    C:\Program Files\IBM\TeamConcertBuild\buildsystem\buildengine\eclipse>jbe -vm "\Program Files\IBM\TeamConcert\jdk\bin\java" -repository https://hostname:port/ccm -userId buildUser -pass buildUser


  6. Configure a Build Engine in Rational Team Concert

Procedure:

Create a new Build Definition:
  1. Create a new Build

  2. Specify the ID

  3. Select Command Line / Jazz Build Engine

  4. Select Next

  5. Select Jazz Source Control

  6. Select Next (Do NOT select any Post Build Options)

  7. Select all default choices in the page called: Additional Configuration::
    General
    Schedule
    Properties

  8. Select Finish

Customize the new Build Definition:
  1. Go to Properties

  2. Add a Build Property of type String with the following details:
    Name: WORKSPACE (This name is referenced inside runAnt.bat, and it refers to the RAD workspace to be created.)
    Value: C:\temp\build (You can change this to any temporary, empty directory.)

  3. Select the workspace from which to build in Jazz Source Control. This is an RTC Repository Workspace. The owner of the workspace must be the same as the user given on the Jazz Build Engine Command line. You can set the owner in the workspace editor.

  4. Enter ${WORKSPACE} in the Load Directory. (This means that RTC will load the contents of the RTC Repository into the location selected to be the RAD Workspace).

  5. Select: Delete Directory before loading to ensure that you build on a new, empty RAD Workspace every time

  6. Specify the following details on the Command Line:
    Command: C:\Program Files\IBM\SDP\bin\runAnt.bat (This is a script contained in the RAD installation directory. Make sure that you select the appropriate path for your installation.)
    Arguments: -buildfile "C:\BuildScripts\build.xml"
    Properties File: C:\temp\build\properties.txt (This is a useful file for debugging: it contains the properties set by JBE when launching the build.)

  7. Select: Add build properties to native environment

  8. Select: Override existing environment variables

  9. Create the sample Build Script C:\BuildScripts\build.xml:


<?xml version="1.0" encoding="UTF-8"?>
<!-- ==============================================================
    ANT Script to be launched by JBE
    ============================================================== -->
<project name="project" default="default">

<property name="runningLocation"
          location="C:/temp/ant-contrib-1.0b3-bin/ant-contrib/ant-contrib-1.0b3.jar" />
<property name="userId" value="buildUser2" />
<property name="password" value="buildUser2" />
<!-- - - - - - - - - - - - - - - - - -
         set the value of the property file
         to the value entered in the
         Build Definition page
         Command Line | Properties file                      
         - - - - - - - - - - - - - - - - - -->
<property file="C:\temp\build\properties.txt" />


<taskdef resource="net/sf/antcontrib/antcontrib.properties">
 <classpath>
  <pathelement location="${runningLocation}" />
 </classpath>
</taskdef>

<!-- =================================
         target: default              
        ================================= -->
<target name="default"
        description="Build: import + compile + check + exit">


 <!-- Build: import + compile + check + exit -->
 <startBuildActivity activityIdProperty="importAndBuildActivityId"
                     label="Import Projects into RAD Workspace and Build"
                     repositoryAddress="${repositoryAddress}"
                     buildResultUUID="${buildResultUUID}"
                     userId="${userId}"
                     password="${password}"
                     verbose="true" />
 <!-- Import Projects  -->
 <projectImport projectname="TestEJBProjClient" />
 <projectImport projectname="TestEJBProjEAR" />
 <projectImport projectname="TestEJBProj" />
 <!-- Build/Compile projects  -->
 <workspaceBuild failonerror="FALSE" />

 <completeBuildActivity activityId="${importAndBuildActivityId}"
                        repositoryAddress="${repositoryAddress}"
                        userId="${userId}"
                        password="${password}"
                        verbose="true"
                        buildResultUUID="${buildResultUUID}" />

 <!-- End the build (with ERROR status if the workspaceBuild task reported errors) -->
 <echo message="The value of the property workspaceErrorCount is ${WorkspaceErrorCount} " />
 <echo message="${WorkspaceErrorMessages}"/>
 <echo message="${WorkspaceErrorMessages}" file="log.txt" append="false"/>
 

 <if>
  <equals arg1="${WorkspaceErrorCount}" arg2="0" />
  <then>
   <echo message="Completing the build with OK state" />

   <logPublisher repositoryAddress="${repositoryAddress}"
                 userId="${userId}"
                 password="${password}"
                 buildResultUUID="${buildResultUUID}"
     filepath="log.txt"
     status="OK"
                 label="OK log" />
  </then>
  <else>
   <echo message="Completing the build with ERROR state" />

   <logPublisher repositoryAddress="${repositoryAddress}"
                 userId="${userId}"
                 password="${password}"
                 buildResultUUID="${buildResultUUID}"
                 filepath="log.txt"
     status="ERROR"
                 label="ERROR log" />
   <!-- This would cause an exception from the if task in the
        workspace .metadata\.log
   <fail message="BUILD FAILED"/>
   -->
  </else>
 </if>

</target>
</project>



Items to customize inside the script:
  1. The properties userId and password should match the corresponding entries specified on the JBE command line.

  2. The property runningLocation  indicates the location where you downloaded the jar file containing the  if  task (Ant-Contrib). See Related information for further details.

  3. You need to specify as many projectImport tasks as projects in your RAD workspace. For each project, specify the projectname. You do not need to specify the project location since RTC copies the projects into the LoadDirectory, which is also used by RAD as the Workspace directory.

Launch the build:

Right click on the Build Definition in the Work Items perspective and select Request Build... > Submit


End of the sample output, if there are build errors:


[workspaceBuild] WorkspaceGetErrors: errors=4 Project=TestEJBProj
[workspaceBuild] WorkspaceGetErrors: errors=0 Project=TestEJBProjEAR
[workspaceBuild] DONE. (errorCount=4)
[completeBuildActivity] Not using a proxy to reach https://localhost:9443/ccm/
[completeBuildActivity] Completing build activity "_QUytavtdEeG0uMLMzkDYMw" for build result "20120910-0835".
[echo] The value of the property workspaceErrorCount is 4
[echo] ERROR: TODO cannot be resolved to a type
[echo] ERROR: Syntax error on token "-", ; expected
[echo] ERROR: generated cannot be resolved to a type
[echo] ERROR: Syntax error on token "stub", ; expected
[echo] Completing the build with ERROR state
BUILD SUCCESSFUL

BUILD SUCCESSFUL
Total time: 2 minutes 29 seconds
HeadlessWorkspaceSettings: RESTORED autoBuild=true maxFile=1048576


Note:
You see: BUILD SUCCESSFUL because the build script contains:

<workspaceBuild failonerror="FALSE" />

The parameter failonerror="FALSE" is required. Otherwise the tasks after workspaceBuild would not be executed in case of a build failure.

You could un-comment the <fail> task inside the <else> task, which would produce the expected message BUILD FAILED However, it would also add an exception from the <if> task in the workspace\.metadata\.log



End of the sample output, if there are no build errors:

[workspaceBuild] WorkspaceGetErrors: errors=0 Project=TestEJBProjClient
[workspaceBuild] WorkspaceGetErrors: errors=0 Project=TestEJBProj
[workspaceBuild] WorkspaceGetErrors: errors=0 Project=TestEJBProjEAR
[workspaceBuild] DONE. (errorCount=0)
[completeBuildActivity] Not using a proxy to reachhttps://localhost:9443/ccm/
[completeBuildActivity] Completing build activity "_M97TuvtnEeG0uMLMzkDYMw" for build result "20120910-0946".
[echo] The value of the property workspaceErrorCount is 0
[echo]
[echo] Completing the build with OK state
BUILD SUCCESSFUL

BUILD SUCCESSFUL
Total time: 2 minutes 23 seconds
HeadlessWorkspaceSettings: RESTORED autoBuild=true maxFile=1048576



Related information

Download Ant-contrib
workspaceBuild task
logPublisher task
ant-contrib.sourceforge.net
RTC 3.0.1.1 Release Notes

Cross reference information
Segment Product Component Platform Version Edition
Software Development Rational Software Architect for WebSphere Software Ant Linux, Windows 8.0.4, 8.0.4.1
Software Development Rational Team Concert Build Linux, Windows 3.0.1.1, 3.0.1.2, 3.0.1.3, 3.0.1.4 Standard, Express-C, Express, Enterprise

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

Rational Application Developer for WebSphere Software
Ant

Software version:

8.0.4, 8.0.4.1

Operating system(s):

Windows

Reference #:

1610613

Modified date:

2013-01-28

Translate my page

Machine Translation

Content navigation