Class GitScanner

java.lang.Object
jenkins.MasterToSlaveFileCallable<LocalGitInfo>
io.jenkins.plugins.gitcollect.GitScanner
All Implemented Interfaces:
FilePath.FileCallable<LocalGitInfo>, Serializable, ControllerToAgentFileCallable<LocalGitInfo>, org.jenkinsci.remoting.RoleSensitive

public class GitScanner extends MasterToSlaveFileCallable<LocalGitInfo>
A file callable that executes on the agent (slave) to extract Git repository information.

This class extends MasterToSlaveFileCallable, allowing it to be sent from the Jenkins controller to the agent where the workspace resides. It interacts with the local file system using the GitClient to resolve revisions and remote URLs.

It returns a LocalGitInfo object containing serializable data about the repository state, which is then sent back to the controller.

See Also:
  • Field Details

    • LOGGER

      public static final Logger LOGGER
  • Constructor Details

    • GitScanner

      public GitScanner(org.jenkinsci.plugins.gitclient.GitClient git, String markedCommit, String remote)
      Constructs a new GitScanner.
      Parameters:
      git - The GitClient initialized for the specific workspace directory.
      markedCommit - A specific commit hash or branch name to resolve as the "marked" revision.
      remote - Specify the remote name
  • Method Details

    • invoke

      public LocalGitInfo invoke(File workspace, hudson.remoting.VirtualChannel channel) throws IOException, InterruptedException
      Executes the scanning logic in the workspace.

      This method performs the following steps:

      1. Retrieves the remote URL for "origin".
      2. Resolves the SHA1 ID for the markedCommit (or HEAD).
      3. Resolves the SHA1 ID for the current HEAD (the built revision).
      4. Constructs Revision objects for both the marked and built states.
      5. Extracts the "humanish" name from the remote URL.
      Parameters:
      workspace - The root directory of the workspace on the agent.
      channel - The virtual channel to the controller.
      Returns:
      A LocalGitInfo object containing the gathered repository data.
      Throws:
      IOException - If an I/O error occurs, or if Git revisions cannot be resolved.
      InterruptedException - If the operation is interrupted.