Jenkins管道和java.nio.file。*方法的問題
這是管道腳本的規范。它寫在@L_419_0@。
readFile步驟從工作空間中加載文本文件并返回其內容 (請勿嘗試使用java.io.File方法-這些將引用Jenkins運行所在的主文件上的文件,而不是當前工作空間中的文件)。
還有一個writeFile步驟可以將內容保存到工作空間中的文本文件中
fileExists 步驟檢查文件是否存在而不加載它。
您可以在節點中使用這些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管道中執行一些基本文件操作。無論代碼所在的節點塊如何,代碼都在主節點上執行。在管道中,我已經驗證了各種節點塊是正確的-它們唯一地標識特定的節點。但是,pathExists(以及其他移動,復制或刪除文件的代碼)始終在主節點上執行。任何想法正在發生或如何解決?
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. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?2. node.js - nodejs開發中常用的連接mysql的庫3. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?4. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處5. 視頻文件不能播放,怎么辦?6. python - 數據與循環次數對應不上7. mysql - 把一個表中的數據count更新到另一個表里?8. 黑客 - Python模塊安全權限9. flask - python web中如何共享登錄狀態?10. mysql 查詢身份證號字段值有效的數據
