Can not cast object 'true' with class' java.lang.Boolean 'to class' groovy.util.slurpersupport.GPathResult

0

I'm launching a jobs of Jenkins that in turn launches a groovy call. This groovy call works perfectly, but not since Jenkins.

The script is:

import groovy.util.XmlParser
import groovy.util.XmlSlurper
import groovy.util.slurpersupport.GPathResult

String xml_steps = new File("/tmp/steps_Devops.xml").text
def GPathResult steps_Devops = new XmlSlurper().parseText(xml_steps)
def GPathResult sUUAA = steps_Devops.children().find { GPathResult node ->
node.name() == 'UUAA' && node.getProperty("@name") == 'EZGN'
}


def GPathResult create_release_structure = sUUAA.children().find { 
GPathResult node ->node.name() == 'Create_release_structure'
}
create_release_structure.text() 

The content of the file is

<Steps_Devops>
    <UUAA name="EZGN" proyect="Nombre Proyecto1">
        <Donwload_Sources>Structure</Donwload_Sources>                       
        <Create_release_structure>Structure</Create_release_structure>                       
        <Deploy_release_artifactory>artifactory</Deploy_release_artifactory>
   </UUAA>
</Steps_Devops>

This returns the "Structure" value that is correct.

However, since Jenkins, the following appears:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'groovy.util.slurpersupport.GPathResult'
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
    at Unknown.Unknown(Unknown)

Data seen in Jenkins:

Pipeline: Groovy    org.jenkins-ci.plugins.workflow:workflow-cps:2.49   MIT License
Groovy CPS Execution    com.cloudbees:groovy-cps:1.24   The Apache Software License, Version 2.0
Pure Java implementation of diff/patch  com.cloudbees:diff4j:1.2    CDDL/GPLv2 dual license

Where can the problem be?

    
asked by Javi Gomez 05.06.2018 в 12:09
source

1 answer

0

Use parentheses to group the condition, where it says:

node.name() == 'UUAA' && node.getProperty("@name") == 'EZGN'

Put it:

((node.name() == 'UUAA') && (node.getProperty("@name") == 'EZGN'))

I think you are solving the condition in the order you do not expect.

    
answered by 28.06.2018 в 14:12