[英]How to deploy Java war file using Jenkinsfile in jenkins pipeline
[英]Using the Groovy Method (Jenkinsfile Pipeline)
def veriableset(){
def a = "test1"
def b = "test2"
def c = "test3"
}
def echomethod(){
echo a
}
node{
stage('test'){
veriableset();
echomethod();
}
}
我想在另一個方法中調用我在方法中定義的變量。
我收到以下錯誤。
[Pipeline] {
[Pipeline] stage
[Pipeline] { (test)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: a for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:270)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:291)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:295)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
at WorkflowScript.echomethod(WorkflowScript:7)
at WorkflowScript.run(WorkflowScript:12)
at ___cps.transform___(Native Method)
我應該使用什么方法? 你能幫助我嗎?
我建議閱讀變量范圍: https://code-maven.com/groovy-variable-scope
刪除 def 的注釋在技術上會很好,但要小心在任何地方使用全局變量。
相反,您可以查看 veriableset() 返回變量並將它們傳遞給 echomethod。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.