Simplest Enterprise Continuous Integration Solutions

Saturday, September 11, 2010

Apache Ant Mail Task

mail_build.xml Ant buildfile contains below contents:
<project name="ant_mail" default="all">
   <target name="mail">
      <mail mailhost="smtp.acme.com" mailport="25" subject="[Ant Mail Notification]: ${my_ant_mail_subject}"
         from="me@acme.com"
         tolist="somebody1@acme.com,some_group1@acme.com"
         cclist="somebody2@acme.com,somegroup2@acme.com"
         encoding="mime" messagemimetype="text/html">
         <message>${my_ant_mail_subject} bla bla =<br><br>
         Regards,<br>
         </message>
      </mail>
   </target>
</project>

Invoked as: 
<full_path_to>/ant -buildfile <full_path_to>/mail_build.xml mail -Dmy_ant_mail_subject="My Email Subject"

Note:
mail.jar and activation.jar existences may require in Ant installation lib folder.

Saturday, September 4, 2010

CruiseControl: CruiseControl 2.8.4 Configuration


[root@fedora12 ~]# uname -a
LINUX FEDORA12.LOCAL.LAB 2.6.31.5-127.FC12.I686.PAE #1 SMP SAT NOV 7 21:25:57 EST 2009 I686 I686 I386 GNU/LINUX

# ANT_HOME

[root@fedora12 ~]# which ant
/usr/bin/ant
[root@fedora12 ~]# ant -version
Apache Ant version 1.7.1 compiled on April 16 2010
[root@fedora12 ~]# echo "export ANT_HOME=/usr/bin/ant" >> /etc/profile
[root@fedora12 ~]# source !$
source /etc/profile
[root@fedora12 ~]# env | grep ANT_HOME
ANT_HOME=/usr/bin/ant

# CruiseControl config/xml

[root@fedora12 ~]# cat /opt/cruisecontrol/config.xml
  <project name="my_cc_project">
    <listeners>
      <currentbuildstatuslistener File="logs/${project.name}/status.txt" />
    </listeners>
    <schedule Interval="300">
      <ant BuildFile="projects/${project.name}/${project.name}_build.xml" AntHome="apache-ant-1.7.1" UseLogger="true" ShowAntOutput="true" UseQuiet="false" />
    </schedule>
    <log>
      <merge Dir="projects/${project.name}/target/test-results" />
    </log>
    <modificationset>
      <filesystem Folder="/mnt/smb_shanred/drop_zone/my_cc_project" UserName="bldmastr" IncludeDirectories="false" />
    </modificationset>
    <publishers>
      <onsuccess>
        <htmlemail MailHost="smtp.fedora12.local.lab" ReturnAddress="cc_admin@fedora12.local.lab" ReturnName="CrusieControl Administrator" SubjectPrefix="[Cruise Control]:" SkipUsers="true" SpamWhileBroken="false">
          <always address="cc_admin@fedora12.local.lab" />
        </htmlemail>
      </onsuccess>
      <onfailure>
        <htmlemail MailHost="smtp.fedora12.local.lab" SubjectPrefix="[Cruise Control]:" ReturnAddress="cc_admin@fedora12.local.lab" ReturnName="CrusieControl Administrator" SkipUsers="true">
          <always address="cc_admin@fedora12.local.lab" />
        </htmlemail>
      </onfailure>
    </publishers>
    <property value="/opt/cruisecontrol" name="cc.dir" />
    <property environment="env" />
  </project>

# CrusieControl project build.xml

[root@fedora12 ~]# cat /opt/cruisecontrol/projects/my_cc_project/my_cc_project_build.xml
<project name="my_cc_project" default="all">


    <property environment="env"/>
    <!-- global configuration -->
    <property name="staging_area_dir" value="/staging_area"/>
    <property name="my_projects_dir" value="/projects"/>
    <property name="drop_zone_dir" value="/mnt/smb_shared/drop_zone/my_cc_project"/>
    <property name="latest_dir" value="/mnt/smb_shared/release_zone/latest"/>


    <!-- local configuration -->
    <property name="project.name" value="my_cc_project"/>
    <property name="my_shortname" value="mcp"/>
    <property name="my_targetos" value="linux"/>
    <property name="my_staging_area_dir" value="${staging_area_dir}/linux/my_cc_project"/>
    <property name="my_staging_area_parent_dir" value="${staging_area_dir}/linux"/>
    <property name="my_project_dir" value="${projects_dir}\Installers\${my_shortname}"/>
    <property name="my_script_dir" value="${projects_dir}\mfg_scripts"/>
    <property name="my_latest_dir" value="${latest_dir}/mcp"/>


    <target name="all" depends="run, copy_readme"/>


    <target name="clean">
        <delete dir="${my_staging_area_dir}" quiet="true"/>
        <delete file="${my_project_dir}/buildlog.xml" quiet="true"/>
    </target>


    <target name="pre-run">
        <mkdir dir="${my_latest_dir}"/>
    </target>


    <target name="generate-manifest">
        <fileset id="manifest.path" dir="${my_staging_area_dir}">
            <exclude name="**/*manifest.txt"/>
        </fileset>


        <pathconvert targetos="${my_targetos}" pathsep="${line.separator}" property="manifest.path.targetos" refid="manifest.path">
           <map from="${my_staging_area_dir}/" to=""/>
        </pathconvert>
        <echo file="${my_staging_area_dir}/manifest.txt">${manifest.path.targetos}</echo>
        <!-- below is for enable the rollback testing -->
        <!--
        <echo file="${my_staging_area_dir}/manifest.txt" append="true">${line.separator}make_rollback</echo>
        -->
    </target>


    <!-- ant invoke cmd: /usr/bin/perl -c ${my_shortname} -d ${drop_zone_dir} -s ${my_staging_area_parent_dir} -r ${my_latest_dir} -p ${project.name} -->
    <target name="run" depends="clean, pre-run">
        <exec executable="/usr/bin/perl">
            <arg value="${my_script_dir}/launch_build.pl"/>
            <arg value="-c"/>
            <arg value="${my_shortname}"/>
            <arg value="-d"/>
            <arg value="${drop_zone_dir}"/>
            <arg value="-s"/>
            <arg value="${my_staging_area_parent_dir}"/>
            <arg value="-r"/>
            <arg value="${my_latest_dir}"/>
            <arg value="-p"/>
            <arg value="${project.name}"/>
        </exec>
    </target>


    <target name="copy_readme">
        <copy file="${my_project_dir}/${my_shortname}_readme.txt" todir="${my_latest_dir}" overwrite="yes"/>
    </target>
</project>