Jenkins管道和java.nio.file。*方法的問題
這是管道腳本的規(guī)范。它寫在@L_419_0@。
readFile步驟從工作空間中加載文本文件并返回其內(nèi)容 (請勿嘗試使用java.io.File方法-這些將引用Jenkins運行所在的主文件上的文件,而不是當前工作空間中的文件)。
還有一個writeFile步驟可以將內(nèi)容保存到工作空間中的文本文件中
fileExists 步驟檢查文件是否存在而不加載它。
您可以在節(jié)點中使用這些Jenkins步驟來代替java.io.File或java.nio.file.Files如下所述。
String slavePath = ’C:Somethingonlyonslavenode’String masterPath = ’D:Somethingonlyonmasternode’stage(’One’) { node (’slave’) {bat returnStatus: true, script: ’set’println fileExists(slavePath) // Should be trueprintln fileExists(masterPath) // Should be false } node (’master’) {bat returnStatus: true, script: ’set’println fileExists(slavePath) // falseprintln fileExists(masterPath) // true }}解決方法
我正在嘗試使用java.nio.file。*中的方法在Jenkins管道中執(zhí)行一些基本文件操作。無論代碼所在的節(jié)點塊如何,代碼都在主節(jié)點上執(zhí)行。在管道中,我已經(jīng)驗證了各種節(jié)點塊是正確的-它們唯一地標識特定的節(jié)點。但是,pathExists(以及其他移動,復制或刪除文件的代碼)始終在主節(jié)點上執(zhí)行。任何想法正在發(fā)生或如何解決?
import java.nio.file.*String slavePath = ’C:Somethingonlyonslavenode’String masterPath = ’D:Somethingonlyonmasternode’def pathExists (String pathName){ def myPath = new File(pathName) return (myPath.exists()) }stage(’One’) { node (’slave’) {bat returnStatus: true,script: ’set’println (pathExists(slavePath)) // Should be true but is false.println (pathExists(masterPath)) // Should be false but is true. } node (’master’) {bat returnStatus: true,script: ’set’println (pathExists(slavePath)) // falseprintln (pathExists(masterPath)) // true }}
相關文章:
1. html5 - css3scale和rotate同時使用轉(zhuǎn)換成matrix寫法該如何轉(zhuǎn)換?2. win10 python3.5 matplotlib使用報錯3. php多任務倒計時求助4. css - 如何把一個視圖放在左浮動定位的視圖的上面?5. javascript - jquery怎么讓a標簽跳轉(zhuǎn)后保持tab的樣式6. MySQL的聯(lián)合查詢[union]有什么實際的用處7. javascript - 小demo:請教怎么做出類似于水滴不斷擴張的效果?8. javascript - vue組件的重復調(diào)用9. python的正則怎么同時匹配兩個不同結(jié)果?10. javascript - axios請求回來的數(shù)據(jù)組件無法進行綁定渲染
