Jenkins:Groovy没有方法签名:static hudson.model.Job.getBuildDir()

时间:2016-01-20 20:14:14

标签: jenkins groovy continuous-integration jenkins-workflow

我正在使用Jenkins 1.6.20测试Workflow Plugin,它使用Groovy来创建你知道的工作。

我正在尝试获取有关当前作业的信息,例如作业的工作目录。

这是我的代码:

import hudson.EnvVars
import hudson.model.*

def build_number = Job.getBuildDir()

echo "$build_number"

它给了我错误:

groovy.lang.MissingMethodException: No signature of method: static hudson.model.Job.getBuildDir() is applicable for argument types: () values: []
Possible solutions: getBuildDir(), getBuilds(), getBuild(java.lang.String), getBuilds(hudson.model.Fingerprint$RangeSet), getRootDir()
    at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1367)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1353)
    at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
    at WorkflowScript.run(WorkflowScript:4)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:69)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:74)
    at sun.reflect.GeneratedMethodAccessor1418.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)

使用此文档:

http://javadoc.jenkins-ci.org/hudson/model/Job.html

我可以读到getBuildDir方法实际上存在,并且错误建议我使用getBuildDir对我没有意义。

1 个答案:

答案 0 :(得分:1)

If it is useful for someone I could get the workspace dir by:

node  {
  def pwdv = pwd()
  echo "path ${pwdv}"
}