Jenkins管道和java.nio.file。*方法的問題
這是管道腳本的規(guī)范。它寫在@L_419_0@。
readFile步驟從工作空間中加載文本文件并返回其內(nèi)容 (請勿嘗試使用java.io.File方法-這些將引用Jenkins運行所在的主文件上的文件,而不是當(dāng)前工作空間中的文件)。
還有一個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é)點塊是正確的-它們唯一地標(biāo)識特定的節(jié)點。但是,pathExists(以及其他移動,復(fù)制或刪除文件的代碼)始終在主節(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 }}
相關(guān)文章:
1. docker鏡像push報錯2. angular.js - angular內(nèi)容過長展開收起效果3. angular.js - angularjs的自定義過濾器如何給文字加顏色?4. python 怎樣用pickle保存類的實例?5. python的前景到底有大?如果不考慮數(shù)據(jù)挖掘,機器學(xué)習(xí)這塊?6. MySQL中無法修改字段名的疑問7. javascript - 微信小程序限制加載個數(shù)8. 大家好,請問在python腳本中怎么用virtualenv激活指定的環(huán)境?9. linux - 升級到Python3.6后GDB無法正常運行?10. 并發(fā)模型 - python將進程池放在裝飾器里為什么不生效也沒報錯
