我试图让当前在我们Jenkins主机上运行的管道脚本,在远程Jenkins节点上执行。但是我遇到了一个奇怪的FileNotFound
异常。
我已经复制出了最基本的流水线版本,并且成功地复现了这个问题:
node("remoteNode") {
env.SERVICE_VERSIONS_FILE = pwd() + '/service_versions.csv'
stage('Read file') {
git credentialsId: '***', url: '***'
sh "cat $env.SERVICE_VERSIONS_FILE"
new File(env.SERVICE_VERSIONS_FILE).each { line ->
echo "$line"
}
}
}
这将导致:
>java.io.FileNotFoundException: /home/***/workspace/DeploymentPipelines/test-deployer/service_versions.csv
> (No such file or directory) at java.io.FileInputStream.open0(Native
> Method) at java.io.FileInputStream.open(FileInputStream.java:195) at
> java.io.FileInputStream.<init>(FileInputStream.java:138) at
> groovy.util.CharsetToolkit.<init>(CharsetToolkit.java:71) at
> org.codehaus.groovy.runtime.ResourceGroovyMethods.newReader(ResourceGroovyMethods.java:1572)
> at
> org.codehaus.groovy.runtime.ResourceGroovyMethods.readLines(ResourceGroovyMethods.java:533)
> at
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.asCollection(DefaultTypeTransformation.java:461)
> at
> org.codehaus.groovy.runtime.DefaultGroovyMethods.iterator(DefaultGroovyMethods.java:15955)
> at org.codehaus.groovy.runtime.dgm$367.doMethodInvoke(Unknown Source)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
> at
> org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:913)
> at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:904)
> at
> org.codehaus.groovy.runtime.InvokerHelper.asIterator(InvokerHelper.java:573)
> at org.codehaus.groovy.runtime.InvokerHelper$asIterator.call(Unknown
> Source) 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
> com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:1890)
> at WorkflowScript.run(WorkflowScript:8) at
> ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
> at
> com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
> at
> com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
> at sun.reflect.GeneratedMethodAccessor324.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.CpsThread.runNextChunk(CpsThread.java:182)
> at
> org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
> at
> org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
> at
> org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
> at
> org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
> at
> org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
> at java.util.concurrent.FutureTask.run(FutureTask.java:266) at
> hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
> 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
sh "cat $env.SERVICE_VERSIONS_FILE"
返回正确的结果(也就是说,它会打印文件内容)。
当在主节点上执行时,该流水线运行良好。感觉可能缺少一些非常简单的东西?还是有bug?