Class FilePathUtils

java.lang.Object
org.jenkinsci.plugins.workflow.FilePathUtils

public class FilePathUtils extends Object
Candidates for inclusion in FilePath. TODO JENKINS-26096
  • Method Details

    • getNodeNameOrNull

      @CheckForNull public static String getNodeNameOrNull(@NonNull FilePath f)
      Looks up the Node.getNodeName() corresponding to a given file. Compared to FilePath.toComputer() this has two advantages:
      • it will still report a configured agent name even if the agent was subsequently disconnected (i.e., the FilePath is invalid)
      • it will still report a node name even if the agent is connected but currently has no executors
      Note that if an administrator disconnects an agent, configures and connects an unrelated agent with the same name, and then this method is called on a path created against the original connection, the result may be misleading.
      Parameters:
      f - a file, possibly remote
      Returns:
      a node name ("" for the controller), if known, else null
    • getNodeName

      @NonNull public static String getNodeName(@NonNull FilePath f) throws IllegalStateException
      Same as getNodeNameOrNull(hudson.FilePath) but throws a diagnostic exception in case of failure.
      Parameters:
      f - a file, possible remote
      Returns:
      a node name ("" for the controller), if known
      Throws:
      IllegalStateException - if the association to a node is unknown
    • find

      @CheckForNull public static FilePath find(@NonNull String node, @NonNull String path)
      Attempts to create a live file handle based on persistable data.
      Parameters:
      node - a name as returned by getNodeName(hudson.FilePath)
      path - a path as returned by FilePath.getRemote()
      Returns:
      a corresponding file handle, if a node with that name is online, else null