NAnt: cannot resolve to boolean value
Asked Answered
T

3

7
<if test="${deployErrors} &gt; 0">
   <fail message="MSDeploy failed" />
</if>

${deployErrors} is populated from a regex capture group and either has a numeric value or empty string. How can I check if this is greater than 0 in a NAnt if block? Here's the error I'm getting if deploy errors contains '1'

'1 > 0' is not a valid value for attribute 'test' of . Cannot resolve '1 > 0' to boolean value. String was not recognized as a valid Boolean.

Templetempler answered 5/5, 2011 at 9:3 Comment(0)
L
8

I've not tried it, but I think you need the whole of your expression within the curly braces:

<if test="${deployErrors > 0}">

See also the second example in the documentation page.

Update from OP:

This worked:

<if test="${deployErrors != ''}">
Levelheaded answered 6/5, 2011 at 9:21 Comment(1)
Thanks, that put me on the right track. I couldn't compare them because the deployErrors would convert to a number. However, comparing it to '' works.Templetempler
A
4

If you need to do something with the actual numeric value then you could do something like this:

<if test="${int::parse('0' + deployErrors) > 10}">
Admiral answered 7/6, 2011 at 18:20 Comment(0)
P
0

Similar to Trystan's answer - to parse a string to a bool, for a string e.g. true, false

<if test="${bool::parse(isEnabled)}">

From http://nant.sourceforge.net/release/0.85/help/functions/bool.parse.html

Phosphorylase answered 18/3, 2014 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.