Class FilePathUtils


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

      • 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
      • 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