ANT build runs fine with WS_ANT but fails in RAD - ant

Just trying to run ANT script with in IBM RAD\RSA 8 to deploy to websphere .
It works fine when run from command prompt using WS_ANT.bat but inside RAD fails with following error
Unable to determine WAS Home directory. Please use the wasHome task attribute or set the was.root System property.
Following is basic ANT script copied from SO and Modified again runs fine from WS_ANT but not from RAD
<?xml version="1.0"?>
<projectname="project"default="wasListApps"basedir=".">
<description>
Script for listing installed apps.
Example run from:
/opt/IBM/SDP70/runtimes/base_v61/profiles/AppSrv01/bin
</description>
<propertyname="was_home"location="C:\Program Files\ibm\SDP80\runtimes\base_v7"/>
<pathid="was.runtime">
<filesetdir="${was_home}/lib">
<includename="**/*.jar"/>
</fileset>
<filesetdir="${was_home}/plugins">
<includename="**/*.jar"/>
</fileset>
</path>
<propertyname="was_cp"value="${toString:was.runtime}">
</property>
<propertyname="was_server"value="server1"/>
<propertyenvironment="env">
</property>
<targetname="wsStopServer">
<taskdefname="wsStopServer"classname="com.ibm.websphere.ant.tasks.StopServer"classpath="${was_cp}">
</taskdef>
<wsStopServerserver="${was_server}"failonerror="false"/>
</target>
<targetname="wsStartServer" depends="wsStopServer">
<taskdefname="wsStartServer"classname="com.ibm.websphere.ant.tasks.StartServer"classpath="${was_cp}">
</taskdef>
<wsStartServerserver="${was_server}"failonerror="true"/>
</target>
<targetname="wasListApps"depends="wsStartServer">
<taskdefname="wsListApp"classname="com.ibm.websphere.ant.tasks.ListApplications"classpath="${was_cp}">
</taskdef>
<wsListAppwasHome="${was_home}"/>
</target>
</project>

If you look at the ws_ant.bat file you will find it calls the setupCmdLine.bat first thing to, you guessed it, setup the command line. That file tries to determine the WAS_HOME environment variable by setting it to the parent directory.
SET CUR_DIR=%cd%
cd /d "%~dp0.."
SET WAS_HOME=%cd%
cd /d "%CUR_DIR%"
This is fine when you run from the command line. You are usually in the ~/SDP/runtimes/base_v7/bin (or other server version) directory. The parent is where you want to be.
I would look into setting the working directory when you run the ws_ant.bat script. That is probably the most likely cause.

Related

Configure Jenkins to deploy PHP project that passed PHPUNit

I have PHP Project, that is hosted on GitHub.
Now, I'd like to configure Jenkins to run unit tests so that:
Whenever developer push/commits code to specific branch, it triggers corresponding PHPUnit build job.
If commit passes the unit tests, the source code is deployed (assuming I already have the required script to deploy).
The question is how to trigger the deployment script when source code passes the unit test (i.e. PHPUnit tests succeed)?
Please suggest to me the way to do that, which plugin I should try to achieve the result?
Thanks!
This is going to be a long post, as there's a lot involved, but it works a treat:
You will need:
Ant
Git Publisher plugin
Ant and phpunit will need to be on your PATH
Step 1: Configure your project
In your Jenkins, configure your project to 'Poll SCM' under the Git option. Leave the 'Schedule' as blank. Under 'branches to build' set that as the branch you want to build your release package from.
Reference:
Step 2: Run ant for every build
Add a build step to 'Invoke Ant'
If you don't use Ant already, create a build.xml file in your project root, add it to Git and have the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<project default="full-build">
<property name="phpunit" value="phpunit"/>
<target name="full-build"
depends="phpunit-unittests,-check-failure"
description="runs the tests"/>
<target name="phpunit-unittests"
unless="phpunit-unittests.done"
description="Run unit tests with PHPUnit">
<exec executable="cmd" failonerror="true" resultproperty="result.phpunit" taskname="phpunit-unittests">
<arg value="/c"/>
<arg value="${phpunit}"/>
<arg value="--configuration"/>
<arg path="${basedir}/phpunit.xml"/>
<arg value="--testsuite=Unit"/>
</exec>
<property name="phpunit-unittests.done" value="true"/>
</target>
<target name="-check-failure">
<fail message="PHPUnit did not finish successfully">
<condition>
<not>
<equals arg1="${result.phpunit}" arg2="0"/>
</not>
</condition>
</fail>
</target>
</project>
That will run all unit tests whenever the Ant task is invoked, which is now set for every time the project is built.
Then, install the Git Publisher tool. Configure as follows:
This creates a new release tag upon a successful build. You will use this later to publish the release to the final location. Note: There are different variables that Git Publisher provides for use, commit hash, user etc so use what you want. I stick to an incremental tag of v1.1.BUILD as that's a bit more standard.
Lastly, you will need to add a Git hook which will trigger a build upon a commit/push from any location.
Navigate to your repository folder and within that the 'hooks' directory.
Create a new file named 'post-receive' (you will see examples in there; overwrite this one). Place the following content in:
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
curl http://YOUR_JENKINS_URL:8080/git/notifyCommit?url=YOUR_GIT_REPOSITORY_URL
fi
done
That should do the job nicely. I have left out implementation details of how you actually release your project as everyone does this differently. There are options to FTP files to a location, and all sorts. Personally I go into the folder where the application resides and do a checkout of the newly created tag - a one line command. Whatever suits your environment.
Other stuff I've ommitted but you will find useful - the Ant build task can do literally anything - In mine, I run composer to install dependences, run bower, run grunt, do syntax checking, coding standard checking, fire up selenium and run web tests, and a load of other stuff. It's a perfect combination of tools to automate the whole project deployment.

Ant inline exec arguments

I have tasks running in Ant, which I'm quite new to, as part of a CI chain of build events. I used a tutorial to create the file for testing/linting/etc a PHP application.
The first important directives in the build.xml are:
<property name="phpmd" value="phpmd"/>
<property name="phpunit" value="phpunit"/>
This works fine as is, assuming that phpmd/phpunit are on the path, and using phpunit as a further example, is run under the following target:
<target name="phpunit" unless="phpunit.done" depends="prepare" description="Run unit tests with PHPUnit">
<exec executable="${phpunit}" resultproperty="result.phpunit" taskname="phpunit">
<arg value="--configuration"/>
<arg path="${basedir}/phpunit.xml"/>
</exec>
<property name="phpunit.done" value="true"/>
</target>
All this works well as is- but I want to use docker from now on, which I had hoped would simply mean changing <property name="phpunit" value="phpunit"/> to <property name="phpunit" value="docker-compose run php phpunit"/>, but this instead gives me the following error:
Execute failed: java.io.IOException: Cannot run program "docker-compose run -w /var/www/src php phpunit" (in directory "/var/lib/jenkins/jobs/Blah blah blah/workspace/src"): error=2, No such file or directory
I know that you would usually add additional <arg/> nodes to targets- but is it not possible at all to provide the full command with inline arguments on the initial <property>?
Ant is obviously complaining because, along with those inline arguments, that executable doesn't exist. Will I have to use arg nodes and update every single target?
Using docker-compose alone works fine, but I need the args for the correct container and working directory to be used- preferably inline, otherwise I have to insert many arg nodes.
In the end I just created a property for phpunit arguments and then added it by using the <args line="${phpunitArgs}">.
Definitely not ideal, but at least it does what it is supposed to. I certainly prefer using Gulp! XML feels like a bad choice for a build system.

ant copy task hanging when the source file is missing

In one of our build script, we have following simple copy task added ->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
This copy task started hanging when the glassfish jar name got changed (version upgrade which are not in our control) at the source location. I was expecting it to error out causing the build failure in that case. Actually at first I was not able to figure out at what particular step build was hanging. Then when I added "-debug" to the ant command and I realized its successfully completing a step prior to this copy task and still there was no trace of copy command that is hung. When I updated the new jar name, it worked fine and build was successful which proved that the copy task is hanging because of filename got changed. To make it easy to debug next time, I added an echo statement like below just prior to that copy task ->
<echo message="Copying glassfish jar to ${targetdir}.."/>
But I am still confused as to why it didn't give error with build failure? I am using Apache Ant version 1.7.1. Could this be a bug? How else I can avoid this situation in future with just the copy task (without using * in the jar name)? TIA
That worked for me. Well, didn't work for me. I got the error message. I am using Ant 1.8 and Ant 1.9.2. I didn't try it with Ant 1.7, but I doubt it's a bug.
Try to use the -v parameter in Ant:
$ ant -v target
And be prepared for a longwinded output. This will give you information what's going on with Ant, and may explain why it's freezing. There's a few things you could do: Use a fileset to specify the file.
<copy todir="${targetdir}">
<fileset dir="${sourcedir}/modules">
<include name="glassfish*.jar"/> <!-- Will catch any glassfish.jar -->
</fileset>
</copy>
Of course, if the file doesn't exist, you won't get an error or even a warning. However, a <fail/> before will detect the issue:
<fail message="missing file ${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar">
<condition>
<not>
<available
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
type="file"/>
</not>
</condition>
</fail>
To force the build to quit, an alternative way
<available file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"
property="glassfish.jaxb.xjc.jar.present"/>
<fail message="you message" unless="glassfish.jaxb.xjc.jar.present"/>
just a few lines less :)
If you want to dig into it, try this:
write a simple build file, which contains only one target with copy, and put it to the same place of your main build file.
<target name="test-copy">
<!-- here use an old (wrong) file name -->
<copy todir="${targetdir}"
file="${sourcedir}/modules/glassfish.jaxb.xjc_1.0.0.0_2-1-12.jar"/>
</target>
run it, check if it fails or hangs.
If this simple build file works, it's very possible that something else in your main build file is causing the bug.

how to start jboss ; how to exclude appxml ; how to make .har file using ant build.xml

How to start and stop Jboss from Command prompt in windows 7 32bit
when i try to run run.bat file from command prompt i get following error
D:\jboss-6.1.0.Final\bin>run.bat
Calling D:\jboss-6.1.0.Final\bin\run.conf.bat
Could not locate "D:\jboss-6.1.0.Final\bin\bin\run.jar".
Please check that you are in the bin directory when running this script.
Press any key to continue . . .
How to start and stop jboss from apache ant build.xml file
How to make .har file for Hibernate project in java using apache ant build.xml
I don't want to include appxml in generated file using ant
appxml="..\PartyEJB\ejbModule\META-INF\ejb-jar.xml"
<ear destfile="${EAR}/PartyEAR.ear" appxml="..\PartyEJB\ejbModule\META-INF\ejb-jar.xml">
<fileset dir="${class}" includes="PartyEJB.jar"/>
<zipfileset dir="${lib.dir}" prefix="lib">
<include name="PartyEJBClient.jar"/>
</zipfileset>
</ear>
set JBOSS_HOME environment variable to D:\jboss-6.1.0.Final and then run run.bat
Verify that in your build.xml you are referring to the bin location directly, where as Ant trying to add bin to the path you have mentioned. Please remove /bin in build.xml from where you are invoking.
If it's a Web-Project or Java EE project, Dynamic Web project which doesn't have EJB's wouldn't require appxml.

Cannot run program "p4": CreateProcess error=2, The system cannot find the file specified

I'm developing automate deployment script for Coldfusion project.
Tool: cruisecontrol.net, ant script
Source control: perforce
Executing the following ant script from cruisecontrol.net i'm getting this error:
"Cannot run program "p4": CreateProcess error=2, The system cannot find the file specified"
But its working fine from command line:
ant -f deployment.xml
deployment.xml file content:
<!-- Get Latest revision from perforce -->
<echo message="Perforce code base Get Latest revision Started"/>
<p4sync port="${p4.server}"
client="${p4.workspace}"
globalopts="${p4.password}"
user="${p4.username}"
view="${p4.branch}"/>
<echo message="Perforce code base Get Latest revision completed"/>
ccnet.config:
<project name="TestMGDeployment">
<triggers>
<intervalTrigger seconds="300" />
</triggers>
<tasks>
<exec executable="C:\Apache\apache-ant-1.8.1\bin\ant.bat">
<baseDirectory>C:\cruisecontrol\Projects</baseDirectory>
<buildArgs>-f deployment.xml</buildArgs>
</exec>
</tasks>
</project>
Thanks,
Nagarajan
Your CruiseControl.net is probably running under different user account, make sure you have p4 in system PATH or specify the full path to the executable in your p4sync task.
Try running in command line instead of as a service to negate user environment definitions issue.
Check if you have setup the P4PORT environment variable. That should be set to: [your perforce server]:[perforce port].
For e.g., P4PORT=perforce.xyz.com:1666

Resources