jenkins pipeline 使用groovy操作文件提示java.io.FileNotFoundException: ×××××.txt (No such file or directory)

java.io.FileNotFoundException: /.........txt (No such file or directory)

at java.io.FileOutputStream.open0(Native Method)

at java.io.FileOutputStream.open(FileOutputStream.java:270)

at java.io.FileOutputStream.<init>(FileOutputStream.java:213)

at java.io.FileOutputStream.<init>(FileOutputStream.java:162)

at java.io.FileWriter.<init>(FileWriter.java:90)

at org.codehaus.groovy.runtime.ResourceGroovyMethods.write(ResourceGroovyMethods.java:740)

at org.codehaus.groovy.runtime.dgm$1036.doMethodInvoke(Unknown Source)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)

at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)

at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:108)

at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)

at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)

at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)

at WorkflowScript.run(WorkflowScript:41)

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.GeneratedMethodAccessor268.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)


源碼:

? ? File file= new File(filePath)

? ??file.write("${env.SQLs}")

『jenkins 一整套測試環(huán)境搭建,pipeline源碼項(xiàng)目請

????添加v:ct-xiaozhou;行業(yè)變遷,多個(gè)好友多點(diǎn)可能性。非機(jī)構(gòu),過來人想要也可以推薦』

直接上原因:

? ? 該方法只在主節(jié)點(diǎn)找文件,該內(nèi)容我是從https://www.it1352.com/1470773.html 上知道的


其他辦法:

????sh "cd whoxin-jenkins/conf && rm -f tempsql.txt && echo ${env.SQLs} >tempsql.txt"

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容