I'm encountering the following:
<target name="test_something">
<if>
<equals arg1="1" arg2="1" />
<then>
<input propertyname="confirm_cleanup" defaultValue="y" validArgs="y,n" promptChar="?">Hello</input>
</then>
</if>
</target>
When I run the task, the output is: HelloHelloHelloHello(y,n) [y]?
Any ideas why it is echoed 4 times?
Cheers
Related
At the moment I'm calling findstr and storing the output in a property to check afterwards - I'm sure there must be a better solution.
<exec program="findstr.exe"
workingdir="${workspaceDir}"
commandline='/i /c:"someText" ${fileName}'
failonerror="false"
output="${coverageExcludeLog}"
resultproperty="foundFile"
/>
Is this really the best way of doing this?
<loadfile file="${fileName}" property="MyFileContents" />
<property name="Mystring" value="someText" />
<property name="search.file" value="${string::contains(MyFileContents, Mystring)}" />
<if test="${bool::parse(search.file)}" > <!-- true or false-->
<echo message="Found the string ${Mystring} in the file ${fileName}" />
</if>
This is my scenario:
I have a build.bat that holds:
call tools\nant-0.92\bin\nant.exe -buildfile:deploy.build %* -logfile:deploy_NAnt.log
Part of deploy.build holds:
<project
name="EdpClient"
basedir="." default="build"
xmlns="http://nant.sf.net/release/0.92/nantContrib.xsd">
<!--INIT -->
...
<property name="version" value="1.48.0.4" />
...
<!--RELEVANT TARGET-->
<target name="BuildProductionApplication" description="Build">
<property
name="publishFolderParameter"
value="/p:PublishDir=${productionPublishFolder}" />
<echo message="Building..." />
<exec
program="${msbuildExe}"
workingdir="." verbose="true">
<arg value="${projectFile}" />
<arg value="/target:Clean;Publish" />
<arg value="${publishFolderParameter}" />
<arg value="/property:ApplicationVersion=${version}" />
<arg value="/property:PublisherName="${publisherName}"" />
</exec>
<echo message="Built" />
</target>
...
</project>
Now my question is:
How can i call "build.bat -version 1.48.0.4" and replace the param
in my structure?
If the -version param is not supplied the script should throw some
sort of msg back in command line?
Thanks to all that help!
This is how i did it:
In deploy.build file i changed:
<property name="version" value="1.48.0.4" />
to:
<property name="version" value="${arg.version}" />
And this is how build.bat (batch) looks like now:
#ECHO OFF
IF %1.==. GOTO ERROR
ECHO:BUILDING VERSION: %1 ...
CALL tools\nant-0.92\bin\nant.exe -buildfile:deploy.build -D:arg.version=%1 -logfile:deploy_NAnt.log
GOTO END
:ERROR
ECHO.
ECHO Please provide the version parameter (eg. "deploy 1.1.1.1")
ECHO.
GOTO END
:END
Now I can call build 1.48.0.4 command.
It suits all my needs.
What I am trying to do, is to find a file with NAnt. This file could by anywhere in a directory structure of a given folder.
I tried to this with the NAnt-foreach task (this works) but I am not quite convinced of that:
<target name="find-file">
<fail message="Property param.dir must be set" unless="${property::exists('param.dir')}" />
<fail message="Property param.pattern must be set" unless="${property::exists('param.pattern')}" />
<property name="return.file" value="" />
<foreach item="File" property="iterator.file">
<in>
<items>
<include name="${param.dir}\**\${param.pattern}" />
</items>
</in>
<do>
<property name="return.file" value="${iterator.file}" if="${string::get-length(return.file) == 0}" />
</do>
</foreach>
</target>
Is there anybody aware of a better approach? If not how can I accomplish to exit the foreach-loop after the first element is found?
This nantcontrib function will put the matching filenames into a delimited string..
If you know that only one matching file will exist then it may get you what you want. If there are several then you could use the nant substring function to just get the first match by taking the substring up to the first delimiter.
The following nant script:
<?xml version="1.0" encoding="utf-8"?>
<project default="find-file2">
<property name="NantContrib.dir" value="C:\Program Files\nantcontrib-0.85\" readonly="true" />
<target name="LoadNantContrib">
<loadtasks assembly="${NantContrib.dir}bin\NAnt.Contrib.Tasks.dll" />
</target>
<target name="find-file2" depends="LoadNantContrib">
<fileset id="find.set">
<include name="${param.dir}\**\${param.pattern}" />
</fileset>
<property name="return.file" value="${fileset::to-string('find.set', ' | ')}" />
<echo message="return.file=${return.file}"/>
<echo message="Found ${fileset::get-file-count('find.set')} files"/>
</target>
</project>
...and the following folder structure:
\---folderroot
+---folder1
| dontfindme.txt
| findme.txt
|
+---folder2
| dontfindme.txt
|
\---folderempty
...works as expected. Searching for findme.txt finds one file. Searching for dontfindme.txt finds two files. Searching for *.txt finds three files.
Example call:
nant -D:param.dir=folderroot -D:param.pattern=findme.txt
Example output:
find-file2:
[echo] return.file=C:\Documents and Settings\rbaker\My Documents\nantfindfile\folderroot\folder1\findme.txt
[echo] Found 1 files
BUILD SUCCEEDED
I need to do a simple addition in NANT program like 1 + 1 =2. I am finding it difficult as every variable is taken as string by default in NANT. I have also tried using int::parse but it did not work.
Regards
Sarathy
Perhaps you can use convert::to-int. There's also an operator overview here.
I also found two examples that perhaps help to understand overall usage (example 1, example 2):
From example 1:
<if test=“${int::parse(UnitTestsResult) != 0}“>
<fail message=“Atleast one unit test failed!“/>
</if>
From example 2:
<target name="repeat">
<property name="var1" value="0" overwrite="false" />
<echo message="${var1}" />
<property name="var1" value="${convert::to-int(var1) + 1)" />
<call target="repeat" if="${convert::to-int(var1) < 10}" />
</target>
<property name="a" value="1"/>
<echo message="${int::parse(a) + 2}" />
Gives:
[echo] 3
How to run NAnt scripts in command line and get the timings of each task on the log file?
using nant <record> task or
NAnt -buildfile:testscript.build testnanttarget
This produces console output but I can't see any timing information.
All I want each log message prefixed with datatime.
You can use the tstamp task to display the current date/time. Just include it everywhere where you want timing information. It will not prefix each line with a timestamp, but at least you can time some strategic points.
<tstamp />
Here is a sample of tstamp
<echo>
-----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
TASK : INITIALIZE
-----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
</echo>
<loadtasks assembly="nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" />
<!-- http://www.basilv.com/psd/blog/2007/how-to-add-logging-to-ant-builds -->
<tstamp>
<formatter property="timestamp" pattern="yyMMdd_HHmm"/>
</tstamp>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<echo message="build.log.filename: ${build.log.filename}" />
<record name="${build.log.dir}/${build.log.filename}" action="Start" level="Verbose"/>
<echo message="Build logged to ${build.log.filename}"/>
<echo message="Build Start at: ${datetime::now()}" />
</target>