how to accept multiple parameters from returning function in groovy

后端 未结 3 1307
终归单人心
终归单人心 2020-12-24 10:40

I want to return multiple values from a function written in groovy and receive them , but i am getting an error

class org.codehaus.groovy.ast.expr.Lis

3条回答
  •  鱼传尺愫
    2020-12-24 11:14

    When running Groovy in the context of Jenkins pipeline job the above answers do not work (at least on version 2.60.2), but the following does:

    node {
        obj = ret2()
        fw = obj[0]
        lw = obj[1]
        echo "fw=${fw}"
        echo "lw=${lw}"
    }
    
    def ret2()
    {
        return [5, 7]
    }
    

    Or alternatively:

    node {
        obj = ret2()
        fw = obj.a
        lw = obj.b
        echo "fw=${fw}"
        echo "lw=${lw}"
    }
    
    def ret2()
    {
        return [a:5, b:7]
    }
    

提交回复
热议问题