Issue with Jenkins pipeline and java.nio.file.* methods

独自空忆成欢 提交于 2019-12-05 07:08:02

This is a specification of pipeline script. It's written in the tutorial.

  • readFile step loads a text file from the workspace and returns its content (do not try to use java.io.File methods — these will refer to files on the master where Jenkins is running, not in the current workspace).

  • There is also a writeFile step to save content to a text file in the workspace

  • fileExists step to check whether a file exists without loading it.

You can use those Jenkins steps in a node instead of java.io.File or java.nio.file.Files as below.

String slavePath = 'C:\\Something\\only\\on\\slave\\node'
String masterPath = 'D:\\Something\\only\\on\\master\\node'

stage('One') 
{
    node ('slave')
    {
        bat returnStatus: true, script: 'set'
        println fileExists(slavePath)     // Should be true
        println fileExists(masterPath)    // Should be false
    }
    node ('master')
    {
        bat returnStatus: true, script: 'set'
        println fileExists(slavePath)     // false
        println fileExists(masterPath)    // true
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!