$ groovy --version
Groovy Version: 2.4.15 JVM: 1.8.0_171 Vendor: Oracle Corporation OS: Mac OS X
I want execute some AWS CLI commands in Groovy, eventually in a Jenkinsfile to run in Jenkins of course.
But for prototyping, I want to code it on my Mac and execute it as a plain Groovy script. So I have this, for example.
#!/usr/bin/env groovy
def getEBSVolumes(awsRegion) {
def regions
if (awsRegion == "all") {
regions = sh(returnStdout: true, script: """#!/usr/bin/env bash
aws ec2 describe-regions --output text|awk '{print \$3}'
"""
)
}
else {
regions = awsRegion
}
echo "Regions: regions"
}
getEBSVolumes("all")
When I execute it, I get
$ ./x.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: x.sh() is applicable for argument types: (java.util.LinkedHashMap) values: [[returnStdout:true, script:#!/usr/bin/env bash
aws ec2 describe-regions --output text|awk '{print $3}'
]]
Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), run(), run(), any(), each(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: x.sh() is applicable for argument types: (java.util.LinkedHashMap) values: [[returnStdout:true, script:#!/usr/bin/env bash
aws ec2 describe-regions --output text|awk '{print $3}'
]]
Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), run(), run(), any(), each(groovy.lang.Closure)
at x.getEBSVolumes(x.groovy:9)
at x$getEBSVolumes.callCurrent(Unknown Source)
at x.run(x.groovy:20)
Can someone please explain the cryptic error message? Thanks!
Note the code works when executed in a Jenkinsfile, hence I specifically asked about CLI Groovy.