user5820327
user5820327

Reputation: 241

Groovy error No signature of method: java.lang.String.call()

Trying to resolve this in the pipeline script, the loop is working but somehow the script is throwing an error at the time of executing shell for each parameter value which is the nodename. The error is

first database
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String, org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [$node, org.jenkinsci.plugins.wor
Possible solutions: wait(), any(), trim(), size(), next(), grep()

The script :

node {
    properties([
    parameters([

booleanParam(name: 'first database', defaultValue: false, description: '') ,
booleanParam(name: 'second database', defaultValue: false, description: '') ,

    ])
])

    stage('Stash') { 
       def list = []
       if("${params['first database']}" == "true") {
           list.add("first database")
       }
       if("${params['second database']}" == "true") {
           list.add("second database")
       }

       list.each { node ->
            echo "$node"
             node('$node') {

     sh """
 echo -e "Hostname:\t\t"`hostname`'

"""

             }
           
            }
       
    }
}

Upvotes: 0

Views: 1500

Answers (1)

ycr
ycr

Reputation: 14604

Your loop variable seems to be conflicting with the node(){} directive. Change the variable name from node to something else. Refer the following.

list.each { nodeName ->
    echo "$nodeName"
    node(nodeName) {
        sh """
          echo -e "Hostname:\t\t"`hostname`'
         """
    }
}

Upvotes: 1

Related Questions