1

I'm new to Groovy and am trying to invoke a Groovy script as a Jenkins Post-build Action, but whenever I run it, I'm getting "ERROR: Failed to evaluate groovy script":

groovy.lang.MissingMethodException: No signature of method: Script1.stage() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, Script1$_run_closure1) values: [branch_1, Script1$_run_closure1@7e39737b] Possible solutions: wait(), any(), isCase(java.lang.Object) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

Here is my code :

def warList1= ["one.war", "two.war", "three.war" ]

def branches = [:] 

for (int i = 0; i < 10 ; i++) {
    int index=i, branch = i+1
        stage ("branch_${branch}"){
            branches["branch_${branch}"] = { 
                node {
                    sshagent(credentials : ['someuser-SSH']){
                        sh "scp ${WORKSPACE}/${warList1[index]} someuser@<somefqdn>:/tmp/pscp/dev"
                    }
                }     
            }
        }
    }
}

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
  • 2
    Can you give us more information ? Like the configuration of the post build action (with the Groovy Posybuild Plugin I presume) and the full stacktrace of the error. – SmartTom May 20 '19 at 15:15
  • groovy.lang.MissingMethodException: No signature of method: Script1.stage() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, Script1$_run_closure1) values: [branch_1, Script1$_run_closure1@7e39737b] Possible solutions: wait(), any(), isCase(java.lang.Object) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) – Chuck Schwing May 20 '19 at 15:35
  • Please edit the question instead of putting further informations in comments. – cfrick May 20 '19 at 15:42
  • The same global vars are not available, I don't use pipeline so I cannot test but you probably need to do something like ```import hudson.model.*``` and maybe ```def build = Thread.currentThread().executable``` or get the stage/branches/node/sshagent objects from somewhere. – gaoithe Feb 07 '20 at 13:47

1 Answers1

1

I think that your issue come from the fact that you can not use stage method in a Groovy Post Build Action. This method is only available in a pipeline script.

SmartTom
  • 691
  • 7
  • 14