Jenkins管道和java.nio.file。*方法的問題
這是管道腳本的規(guī)范。它寫在@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步驟來代替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é)點(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. Python從URL中提取域名2. php傳對(duì)應(yīng)的id值為什么傳不了啊有木有大神會(huì)的看我下方截圖3. python - scrapy url去重4. python - Flask寫的注冊(cè)頁面,當(dāng)注冊(cè)時(shí),如果填寫數(shù)據(jù)庫里有的相同數(shù)據(jù),就報(bào)錯(cuò)5. 關(guān)于mysql聯(lián)合查詢一對(duì)多的顯示結(jié)果問題6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. 數(shù)據(jù)庫 - Mysql的存儲(chǔ)過程真的是個(gè)坑!求助下面的存儲(chǔ)過程哪里錯(cuò)啦,實(shí)在是找不到哪里的問題了。8. python - oslo_config9. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)10. 小白學(xué)python的問題 關(guān)于%d和%s的區(qū)別
