Jenkins管道和java.nio.file。*方法的問(wèn)題
這是管道腳本的規(guī)范。它寫(xiě)在@L_419_0@。
readFile步驟從工作空間中加載文本文件并返回其內(nèi)容 (請(qǐng)勿嘗試使用java.io.File方法-這些將引用Jenkins運(yùn)行所在的主文件上的文件,而不是當(dāng)前工作空間中的文件)。
還有一個(gè)writeFile步驟可以將內(nèi)容保存到工作空間中的文本文件中
fileExists 步驟檢查文件是否存在而不加載它。
您可以在節(jié)點(diǎn)中使用這些Jenkins步驟來(lái)代替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í)行一些基本文件操作。無(wú)論代碼所在的節(jié)點(diǎn)塊如何,代碼都在主節(jié)點(diǎn)上執(zhí)行。在管道中,我已經(jīng)驗(yàn)證了各種節(jié)點(diǎn)塊是正確的-它們唯一地標(biāo)識(shí)特定的節(jié)點(diǎn)。但是,pathExists(以及其他移動(dòng),復(fù)制或刪除文件的代碼)始終在主節(jié)點(diǎn)上執(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. gosts內(nèi)容是空的2. javascript - 怎樣在vue組件中優(yōu)雅的獲得vuex中的state的值3. mysql - 記錄開(kāi)始時(shí)間和結(jié)束時(shí)間,表字段類型用timestamp還是datetime?4. javascript - 微信小程序電商務(wù)搜索頁(yè)排序功能的邏輯5. javascript - JS垃圾回收機(jī)制6. 我的怎么不顯示啊,話說(shuō)有沒(méi)有QQ群什么的7. javascript - 使用node如何進(jìn)行前后臺(tái)分離?8. javascript - 百度鏈接尾部的這個(gè)參數(shù)是干嘛的?9. javascript - vue項(xiàng)目 npm run dev報(bào)錯(cuò)10. 為啥總顯示密碼錯(cuò)誤
