簡體   English   中英

無論如何我可以從 groovy 關閉中獲得價值

[英]Is there anyway i can get value from groovy closure

我有一個如下的閉包,我想從 a、b、c 中獲取價值。

#!/usr/bin/env groovy
entry {
    a = false
    b = "nodejs"
    c = "xxx"
}
println entry.a
println entry.b
println entry.c

有什么辦法可以做到這一點? 我總是收到如下錯誤

% groovy jenkinsfile.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: jenkinsfile.entry() is applicable for argument types: (jenkinsfile$_run_closure1) values: [jenkinsfile$_run_closure1@12aba8be]
Possible solutions: every(), every(groovy.lang.Closure), any(), any(groovy.lang.Closure), notify(), identity(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: jenkinsfile.entry() is applicable for argument types: (jenkinsfile$_run_closure1) values: [jenkinsfile$_run_closure1@12aba8be]
Possible solutions: every(), every(groovy.lang.Closure), any(), any(groovy.lang.Closure), notify(), identity(groovy.lang.Closure)
    at jenkinsfile.run(jenkinsfile.groovy:2)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

我必須使用這種方式,因為我有很多以這種格式編寫的 Jenkinsfile,我想從 Jenkinsfile 中獲取值。 這是來自 Jenkinsfile 的格式。

您如何為此使用 map 文字:

entry = [
    a:false,
    b:"nodejs",
    c:"xxx"
]
println entry.a
println entry.b
println entry.c

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM