Execute ms dos batch script from cruise control and pass variables - environment-variables

I am trying to execute a msdos batch script from cruise control and pass some variables. I can execute the batch script fine but I can't access the environment variables in the batch script. Here's what my ccnet config file has:
<exec>
<executable>myscript.BAT</executable>
<environment>
<variable name="var1" value="value1" />
<variable name="var2" value="value2" />
</environment>
</exec>
How can I access var1 and var2 in myscript.BAT? All I get when I do "%var1%" is blank.

You can also pass in your values as parameters and reference var1 and var2 by $1 and $2 respectively.

Related

Jmeter remote Execution -- Is there any way to provide global property from ant?

In my Jmeter script
I'm using property function i.e. ${__P(varName,2)} to specify variable value at run time.
When Executing script from CMD --
I can specify property value using -JvarName (i.e. -JvarName=5) and
for remote Execution I can specify value using -GvarName (i.e. -GvarName=5)
from CMD.
Now I'm trying to run this Jmeter script using ant build
and
It's working fine on single PC. (i.e. runremote="false")
But when I try to execute remotely on multiple PC (i.e. runremote="true")
It Doesn't take values provided in property tag (i.e.<property name="varName" value="5"/>)
is there any way to provide global property from ant.??
just like we do from CMD using argument -G .
<target name="JMeter" depends="start">
<taskdef name="jmeter"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask">
</taskdef>
<jmeter jmeterhome="${jmeter_Home}"
resultlog="${report.output.location}/Report/${property.file}/${START_TIME}/JMete‌​rSummeryResults.jtl"
runremote="true">
<testplans dir="../JMeter" includes="*.jmx" />
<property name="USERS" value="${thread.users}" />
<property name="SITE_ID" value="${site.id}" />
<property name="FOLDER_ID" value="${folder.id}" />
<property name="FILE_PATH" value="${file.upload.path}" />
</jmeter>
There is a remote attribute which needs to be set to true.
<property name="varName" value="5" remote="true"/>

How to control the command shell through ant?

currently im calling a batch script(__Make.bat) through exec task which starts GNUMake related tasks.
After i invoke build.xml file directly from the command line the batch script gets called where a new command shell is shown and before the batch script completes its operation the ant execution is closed.
Based on the output of the batch script im calling junit results task for generating the report.
So currently the batch script is independent of ant shell.
Could you please let me know is there any option to control the batch script so that after it completes its operation the junit results gets called.
snippet:
<!-- Macro to execute batch script from every testcase-->
<macrodef name="executeTarget">
<attribute name="option" default="NOT SET"/>
<sequential>
<exec dir="${baseLoc}/Temp/${ant.project.name}/${testDataZipFile}/MakeWare/BCU_MakeWare" executable="cmd" vmlauncher="true" os="Windows XP">
<env key="WAHL" value="#{option}"/>
<arg line="/c "/>
<arg value="start __Make.bat"/>
</exec>
</sequential>
</macrodef>
regards,
kiran
Pass the /WAIT option to start:
<arg value="start /WAIT __Make.bat"/>
Start command: Microsoft's documentation

How to run testcases/classes as per order in testng.xml through command prompt by ant?

I have 20 test cases in testng.xml file. The names are not in alphabetical order but in logical manner. When i execute from command prompt by Ant, test cases are executing by alphabetical order .
how can i execute test cases or classes in testng as in same order from command prompt by ant.
Kindly help me out.
You can use the preserve-order attribute. Here's an example:
<test name="MyTest" preserve-order="true">
<classes>
<class name="com.simple.test.Test1" />
<class name="com.simple.test.Test2" />
<class name="com.simple.test.Test3" />
</classes>
</test>

How to write a variable in to file in ant?

i have a variable abc and had the value this is ant script. This abc variable will keep on changing.
Using ANT script, how can i write the value out to the file?
The echo task in ANT is able to write to files
<echo file="output.txt" append="true">
abc=${abc}
</echo>
Use propertyfile task. An example taken from ant manual:
<propertyfile file="my.properties">
<entry key="abc" value="${abc}"/>
</propertyfile>
This may be better than echo as it updates the properties file with a given value, while echo appends to or overwrites the whole file.

Sourcing a shell profile in an ant build file?

I am using cruisecontrol and ant to build some legacy executables that also depend on a shell profile to setup env vars properly. Is there a way to exec this profile using ant in the current process so the makefiles ant calls get the env vars correctly?
Another solution would be if there is a way to add the profile sourcing to the sub make files I'm calling.
Edit: I guess I wasn't clear in my question. I know what env varibles need to be passed to make using the exec/env tasks. However, I don't know how to have ant grab the values from a shell profile that is usually sourced via: . /usr/local/profile/foo.profile
I figured out how to do it based off of how ant itself sources env variables.
<exec executable="ksh" dir="${foo.dir}"
failonerror="true" output="${foo.dir}/env.properties">
<arg value="-c" />
<arg value=". /usr/local/profiles/profile.foo; set" />
</exec>
<property file="${foo.dir}/env.properties" prefix="env"/>
Further down I can then pass them to sub make calls using the exec tags. For example:
<exec executable="make" dir="${bar.dir}" failonerror="true">
<env key="ORACLE_HOME" value="${env.ORACLE_HOME}" />
</exec>
You will not be able to execute make in the current process.
Take a look at the ant <exec> task, use this to execute your make build. The environment variables will still be available for the make process, in fact you can turn this off explicitly with the newenvironment attribute. The following simple exec should retain all environment variables in make:
<exec executable="make" />
If you need extra environment variables, or want to maintain them through your ant build you can use them in the exec task by adding <env> elements like so:
<exec executable="make" >
<env key="ENV_KEY" value="ENV_VALUE"/>
</exec>

Resources