首页 > 解决方案 > 没有方法签名:collectLogs.call() 适用于参数类型

问题描述

嗨,我尝试运行从附加文件中收集日志的 groovy 脚本

#!/usr/bin/env groovy
import static groovy.io.FileType.FILES
def call() {
    def CURRENT_DIRECTORY_PATH = 'automation-system-tests/ansible/appli'
    def ZIP_NAME = 'appLogs.zip'
    def FULL_LOGS_PATH = new File("/var/log/full.log")
    def LOG_LIST = []

new File("/var/log/").traverse(type: groovy.io.FileType.FILES, nameFilter: ~/app.*.log/) { next ->
     LOG_LIST << next
      }
 LOG_LIST.each{ FULL_LOGS_PATH.append(it.text) }

    echo 'Collecting Logs from the machine'
    collectLogs(FULL_LOGS_PATH, ZIP_NAME)
    archiveArtifacts artifacts: "${CURRENT_DIRECTORY_PATH}/machineLogs/**/*", allowEmptyArchive: true
}

我收到了这个错误

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: collectLogs.call() is applicable for argument types: (java.io.File, java.lang.String) values: [/var/log/full.log, appLogs.zip]
Possible solutions: call(java.lang.String, java.lang.String), wait(), any(), run(), run(), collect()
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
    at collectPublishLogs.call(collectPublishLogs.groovy:23)
    at WorkflowScript.run(WorkflowScript:269)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor210.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
    at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
    at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:136)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

是同样的问题还是其他问题,你能告诉 詹金斯 groovy MissingMethodException 没有方法的签名

标签: jenkinsgroovyjenkins-groovy

解决方案


错误指出:

No signature of method: collectLogs.call() is applicable for argument types: (java.io.File, java.lang.String) values: [/var/log/full.log, appLogs.zip]
                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Possible solutions: call(java.lang.String, java.lang.String), wait(), any(), run(), run(), collect()
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

如建议的那样,第一个参数不能是Filebut String。例如使用:

collectLogs(FULL_LOGS_PATH.toString(), ZIP_NAME)

或者,如果其他地方允许,直接为您的变量使用字符串。


推荐阅读