exception while executing groovy script from jenkinsfile groovy.lang.MissingPropertyException: No such property: args for class: groovy.lang.Binding
The problem is that in myGroovyScript.groovy
you use def service = args[0]
but args
variable is not defined anywhere.You can define it as a global variable in Jenkinsfile this way
//...args = ['abcd'] //note you have to define it without def to make it globaldef example = load "${rootDir}myGroovyScript.groovy" //...
But using global variables is error prone and not recommended. The better way would be wrapping myGroovyScript.groovy
into function and then call it and pass service as parameter. Something like thismyGroovyScript.groovy
:
#!/usr/bin/env groovydef execute(service) { def maxAttempt = 90 def attempt = 1 def frontDoorUrl def waitTimeMS = 10000 def uiNodes def uiNodesReady = false def uiFrontDoorReady = false // all code go into function and ramain the same}return this // you also need to return a reference to this script
And then in Jenkinsfile
def example = load "${rootDir}myGroovyScript.groovy"example.execute('abc')