JMeter overriding properties with spaces in non GUI mode with ANT - ant

I need to pass parameter values to jmeter properties like this:
#echo off
cd E:\apache-jmeter-2.11\bin
jmeter.bat -n
-t E:\OMS.P01-AccountCreation.jmx
-l E:\result.csv
-j E:\jmeter.log
-Jthreadgroup.count=1
-JPRIMARY_STREET_NUMBER=1234
-JPRIMARY_STREET_NAME=DONALDTRUMP AVENUE
But this will fail as the name 'DONALDTRUMP AVENUE' has an space. It will try to read 'AVENUE' as a different parameter. Is there any way to make it read as a whole value? thanks
EDIT
It works if I add "" to enclose it. However, when I try the same thing with ANT, it throws the same error. Does anyone knows how can I solve it?
EDIT 2
I tried again with command line instead of ant. I think I found the problem. I cant add too many parameters (I'm adding like 22 parameters) I'm not sure if there is a parameter limit or if there is a length limit for the whole command line.

I don't know how you're passing properties to Ant but normally smart people don't have any problems with spaces in property values. Are you aware that:
Ant doesn't know anything regarding -J command line argument
Ant knows nothing about JMeter properties
So if you need to pass to JMeter something you can change via Ant command-line you need to do something like:
In build.xml
<target name="jmeter">
<jmeter
jmeterhome="/path/to/your/jmeter"
testplan ="OMS.P01-AccountCreation.jmx"
resultlog="result.jtl">
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.bytes" value="true"/>
<property name="threadgroup.count" value="${threadgroup.count}"/>
<property name="PRIMARY_STREET_NUMBER" value="${PRIMARY_STREET_NUMBER}"/>
<property name="JPRIMARY_STREET_NAME" value="${PRIMARY_STREET_NAME}"/>
</jmeter>
</target>
When launching JMeter test via Ant:
ant -Dthreadgroup.count=1 -DPRIMARY_STREET_NUMBER=1234 -DPRIMARY_STREET_NAME="DONALDTRUMP AVENUE"
References:
Command prompt (Cmd. exe) command-line string limitation
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Related

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.

How to give a custom path for ivy:retrieve

I'm using Jenkins, Ivy and Ant for my builds.
I have the following lines:
<echo>${env.WORKSPACE}\${componentname}.Test.Unit\lib\</echo>
<ivy:retrieve pattern="${env.WORKSPACE}\${componentname}.Test.Unit\lib\[artifact].[ext]" transitive="false"/>
echo returns this:
[echo] C:\Jenkins\workspace\Productv1.0~Common.Utility\Common.Utility\lib\
But the retrieve call doesn't seem to place the libraries there.
Is this possible with the pattern parameter or am I using it wrong?
Works fine for my on Linux
<echo>${env.HOME}/tmp/Test.Unit/lib/</echo>
<ivy:retrieve pattern="${env.HOME}/tmp/Test.Unit/lib/[artifact].[ext]" transitive="false"/>
Files are placed where I expect them:
$ find /home/mark/tmp/Test.Unit/lib/
/home/mark/tmp/Test.Unit/lib/
/home/mark/tmp/Test.Unit/lib/commons-lang.jar
/home/mark/tmp/Test.Unit/lib/junit.jar

Which Ant property contains the CWD when the ant script is run?

I don't want to get the basedir -- that appears to contain the build.xml script -- I want the CWD of the call to ant itself.
Basically, I want to do this:
$ cd /home/chrisr/projects/some_project
$ ant -f ../../tools/ant-build-rules/library.xml build-library
At this point, I need two things:
The path to ant-build-rules in absolute form; this is currently found in the basedir property, so I'm set there.
The path of some_project, in absolute form. This is what I don't know how to get.
Which property contains this information?
The java property user.dir contains the current directory
<project name="demo" default="printCWD">
<target name="printCWD">
<echo message="${user.dir}"/>
</target>
</project>
There is no such property, but you can run a script to get it.
${bsh:WorkDirPath.getPath()}
See urbancode.com.

How to enable verbose output using the ant task and inheritall="false"

When starting a build in verbose mode (ant -v) the verbose mode is not propagated to the "subants". The ant task looks like this:
<ant antfile="${buildproject}" inheritall="false" target="${target}" output="${output.file}">
<property name="repo.global" value="/repo"/>
<property name="proj.property.prefix" value="${property_prefix}"/>
</ant>
We don't want to propagate all properties because we try to remove an old build system. Any ideas how to preserve the "verbose" output without using the exec task?
I had to deal with something similar just last month. You probably need to define you own task to change the loglevel in a script. The following blog entry (http://codefeed.com/blog/?p=82) helped a lot. The author provides all the necessary source code.
If you don't want to create your own task with all that hassle, there is a embedded-javascript-snippet answer in this SO-question.

Passing filepath to ANT from BAT script

I am trying to invoke an ANT target from Windows (right-click) file context menu.
I have setup the registry entries to invoke a batch script which invokes my ANT EXEC target.
I need to pass the path of the file (on which user right-clicked) to my ANT target. So I am using %~dp1 to set an ANT properties in my bat script:
Set tobeusedfilepath=%~dp1
Set tobeusedfile=%~n1
resulting in:
tobeusedfilepath=D:\Project\Rel L\
tobeusedfile=file
The problem is %~dp1 returns a string with "\" as file separator. But ANT EXEC task wants "/"
[exec] '-source'
[exec] 'D:ProjectRel L/file'
[exec] ......
[exec] The file, 'D:ProjectRel L/file', does not exist.
Any suggestions how to get around this path separators?
set AntPath="D:\Project\Rel L\"
set AntPath=%AntPath:\=/%
set AntPath=%AntPath::/=:%
gives
set AntPath="D:\Project\Rel L\"
set AntPath="D:/Project/Rel L/"
set AntPath="D:Project/Rel L/"
If you are running on Windows Ant will happily accept OS directory separator which is \.
Upon examination of the output of your program I see that the path separators are missing: you have D:ProjectRel not D:\Project\Rel. I may only guess that you are trying to exec a Cygwin program. Cygwin programs will use \ as an escape character. Therefore you need to use a <pathconvert> property to adjust the directory separators.
Code snippet below illustrates how to do this
<property name="tobeusedfilepath" location="D:\Project\Rel L\"/>
<property name="tobeusedfile" value="file"/>
<property name="system-path-filename"
location="${tobeusedfilepath}/${tobeusedfile}"
/>
<pathconvert property="unixized-filename" targetos="unix">
<path location="${system-path-filename}"/>
</pathconvert>
<echo message="system-path-filename=${system-path-filename}"/>
<echo message="unixized-filename=${unixized-filename}"/>
And here is the output of this run:
[echo] system-path-filename=D:\Project\Rel L\file
[echo] unixized-filename=D:/Project/Rel L/file

Resources