Liferay Jenkins ant build  integration Part2

This is Liferay Jenkins ant build integration part2 tutorial, as explained in the previous tutorial about Liferay jenkins integration process. In this tutorial, we will look into ant script for liferay plugin sdk.

  •  Ant Build script
  • Jenkins build process
  • Jenkins deployment process with Build Pipeline plugin
  1. Ant Build Script Development: In this we will learn about build script implementation for liferay. Liferay provides ANT scripts for Service Builder, building plugins and deploying plugins .
  • The below script contains below ant build targets
    • Init 
      • creates build,dist directories in Jenkins workspace
      • extracts /config/bundle/liferay-tomcat/liferay-portal-tomcat-6.2-ee-sp11 into  build directory. Liferay Plugin SDK  ANT scripts requires Liferay tomcat libraries(tomcat\lib\ext) & jars to execute scripts.That’s a reason we are extracting  liferay tomcat while building project artifacts
      • creating and copying build.{user-name}.properties file
    • Build Services –  Why build services is required??  Service builder generate service.properties file to keep track builder number.When  a new build number found then it will upgrade database. When multiple developer works they would commit to SVN with their local service.properties file and will give error while deploying plugin.  so this need to be controlled in Jenkins to maintain service-ext.properties file to override service.properties and then  build service artifacts with this.
      • Copy service-ext.properties file from /config/common to
      • Delete *-service.jar from  sdk/portlets/**/**/*service.jar
      • Invoke liferay plugin sdk “build-services” target
    • Liferay bundle-build – In this step invoke lifray plugin sdk ant target to do build
    • Create Tar ball:
        • copy liferay-sdk-plugins/dist to Jenkins-workspace/dist folder

      create tar ball project-{svn_revision}-{build-number}

We will create build structure in “D:\work\jenkind-build” folder. Later this folder will be selected as Jenkins workspace in Jenkins Advanced configuration

    • Create a directory structure like shown in below:
    • Create a config directory structure below

      Config folder structure

    • build.properties files

project.dir=liferay-plugins-sdk
build.dir=build
config.path=config
dist.dir=dist
liferay.bundle=bundle/liferay-portal-tomcat-6.2-ee-sp11.zip
liferay.portal.folder=liferay-portal-tomcat
liferay.portal.dir=${basedir}\\${build.dir}\\${liferay.portal.folder}

  • Add below xml element to access jenkins environmental variables
  •  <!-- To load Jenkins related properties -->
    <property environment="env"/>
  • Ant script(build.xml) file at Jenkins Home . Please download from Jenkins Config

 <?xml version="1.0"?>
 <!DOCTYPE project>
 <project name="portal" default="build" basedir=".">
 <!-- To load Jenkins related properties -->
 <property environment="env"/>
 <property file="build.properties"/>
 <path id="project.path">
 <pathelement path="${basedir}\${project.dir}"/>
 </path>

<path id="portal.dir">
 <pathelement path="${liferay.portal.dir}"/>
 </path>
 <pathconvert targetos="windows" property="project.basedir" refid="project.path"/>
 <pathconvert targetos="windows" property="widnows.liferay.portal.dir"  refId="portal.dir">
 <filtermapper>
 <replacestring from="\" to="\\" />
 </filtermapper>
 </pathconvert>
 <property name="config.dir" value="${basedir}\${config.path}"/>

<target name="init">
 <echo>${widnows.liferay.portal.dir}</echo>
 <!--<delete dir="${build.dir}" /> -->
 <mkdir dir="${build.dir}"/>
 <mkdir dir="${dist.dir}" />
 <unzip src="${config.dir}\${liferay.bundle}"  dest="${build.dir}" overwrite="false" >
 <patternset>
 <include name="**/tomcat-7.0.42/**"/>
 </patternset>
 <regexpmapper from="^[^/]+/(.*)$" to="liferay-portal-tomcat/\1"/>
 </unzip>
 <mkdir dir="${liferay.portal.dir}/deploy"/>
 <echo file="${project.basedir}/build.${user.name}.properties">
 app.server.tomcat.lib.global.dir =${widnows.liferay.portal.dir}\\tomcat-7.0.42\\lib\\ext
 app.server.tomcat.deploy.dir = ${widnows.liferay.portal.dir}\\tomcat-7.0.42\\webapps
 app.server.parent.dir = ${widnows.liferay.portal.dir}
 app.server.tomcat.dir = ${widnows.liferay.portal.dir}\\tomcat-7.0.42
 app.server.type = tomcat
 app.server.tomcat.portal.dir =${widnows.liferay.portal.dir}\\tomcat-7.0.42\\webapps\\ROOT
 </echo>
 <!-- <copy file="${config.dir}\${liferay.build.file}" todir="${project.basedir}"  verbose="true" /> -->
 <!-- <copy file="${config.dir}\${liferay.bundle}" todir="${build.dir}" verbose="true" overwrite="false"/> -->
 </target>
 <!--- Called at init tager -->
 <target name="unzip-liferay-bundle">
 <unzip src="${config.dir}\${liferay.bundle}"  dest="${build.dir}" overwrite="false" >
 <patternset>
 <include name="**/tomcat-7.0.42/**"/>
 </patternset>
 <regexpmapper from="^[^/]+/(.*)$" to="liferay-portal-tomcat/\1"/>
 </unzip>
 </target>

<target name="build" depends="init,build-service,copy-service-jar-ext,build-plugins">
 <echo >Creating TAR Ball </echo>
 <tar destfile="${basedir}\${dist.dir}\portal_build_${env.SVN_REVISION}_${env.BUILD_NUMBER}.tar" longfile="gnu">
 <tarfileset dir="${basedir}\${build.dir}">
 <!---  <include name="ext/**"/> -->
 <include name="liferay-portal-tomcat/deploy/**"/>
 </tarfileset>
 </tar>

</target>

<target name="build-plugins">
 <ant dir="${project.basedir}" inheritAll="false" />
 </target>

<target name="clean" depends="clean-service-jar">
 </target>

<target name="build-service" depends="clean-service-jar,copy-build-number,build-service-jar,copy-service-jar">
 </target>

<target name="copy-service-jar-ext" >
 <copy todir="${basedir}/${build.dir}/${liferay.portal.folder}/tomcat-7.0.42/lib/ext" verbose="true" overwrite="true" flatten="true">
 <fileset dir="${basedir}/${build.dir}/ext" >
 <filename name="**/*service.jar"/>
 </fileset>
 </copy>
 </target>

<target name="build-service-jar">
 <ant dir="${project.dir}" inheritAll="false" >
 <target name="build-service"/>
 </ant>
 <echo>Complted Building Service Jars</echo>
 </target>
 <target name="copy-build-number">
 <echo>Copying Service-ext.properties files to portlets src directory</echo>
 <copy file="${config.dir}\common\service-ext.properties" overwrite="true"  verbose="true" todir="${project.basedir}\portlets\test-portlet\docroot\WEB-INF\src" />
 <copy file="${config.dir}\common\service-ext.properties" overwrite="true"  verbose="true" todir="${project.basedir}\portlets\test2-success-portlet\docroot\WEB-INF\src" />
 <copy file="${config.dir}\common\service-ext.properties" overwrite="true"  verbose="true" todir="${project.basedir}\portlets\test3-portlet\docroot\WEB-INF\src" />
 <copy file="${config.dir}\common\service-ext.properties" overwrite="true"  verbose="true" todir="${project.basedir}\portlets\test4-portlet\docroot\WEB-INF\src" />

</target>
 <target name="copy-service-jar" >
 <echo>Copying  Service Jars from libs to etc folder</echo>
 <copy todir="${basedir}/${build.dir}/ext" verbose="true" overwrite="true" flatten="true">
 <fileset dir="${project.basedir}"  includes="**/*">
 <filename name="**/*service.jar"/>
 </fileset>
 </copy>
 </target>
 <target name="clean-service-jar">
 <echo>Cleaning Service Jars</echo>
 <delete verbose="true">
 <fileset dir="${project.basedir}" includes="\portlets\**\docroot\WEB-INF\lib\*service.jar" />
 </delete>
 </target>

</project>

 

In next tutorial we will see Jenkins build job integration and download config from here

Thanks.

 

1 Comment

  1. Pingback: liferay jenkins integration

Leave a Comment

Your email address will not be published. Required fields are marked *