Search code examples
xmljenkinsjellyjenkins-email-extemail-publisher

compare 2 variables in jelly script


<j:set var="maxEachOSTime" value="0" />
<j:if test="${xmlval &gt; maxEachOSTime}">
    ${xmlval} &gt; ${ maxEachOSTime}
    <j:set var="maxEachOSTime" value="${xmlval}"/>
    <j:set var="finalTotalDuration" value="${total_duration}"/>
</j:if>

if ${xmlval} is compared with a number ( 1, 200, etc) it works. But when compared with ${eachMaxOSTime} it doesnt work. (condition is always working as true) .intValue() also didnt help. What is the solution for this?


Solution

  • This is what that finally helped me in my specific use case.

    xmlval is variable which has integer value by reading from xml file

    maxEachOSTime var was set as string by default via <j:set>

    Converted that into float and used its intValue()

    Earlier intValue() was not working as String didnt have attribute intValue, hence the if condition was getting skipped.

    This can be improvised by working directly into integers

    <j:new className="java.lang.Float" var="tempFloat">
        <j:arg value="${maxEachOSTime}" type="float"/>
    </j:new>
    <j:set var="intThing" value="${tempFloat.intValue()}"/>
    <j:if test="${xmlval &gt; intThing}">
        <j:set var="maxEachOSTime" value="${xmlval}"/>
        <j:set var="finalTotalDuration" value="${total_duration}"/>
    </j:if>