Search code examples
jenkinsjenkins-pluginsjenkins-pipeline

Does fileExists work on Jenkins slaves or only on master?


Relevant link

If I run straight groovy (using file()) it will only run on master. To check for a file on slave I have to use shell, but what about this function?

Will fileExists() work on a slave and find the file on slave workspace?


Solution

  • It is true that groovy methods in the global vars will execute only on the master. However, fileExists and all other methods that are part of the Jenkins Declarative DSL will execute on the current build server where the job is being performed and in the workspace.

    In essence, any Jenkins Declarative DSL method provided by a plugin (note the plugin for the method you referenced is here) will execute on the build server. Groovy methods within global vars will still execute on the Jenkins master.