Class CollectGitStep

All Implemented Interfaces:
ExtensionPoint, Describable<Builder>, BuildStep, SimpleBuildStep

public class CollectGitStep extends Builder implements SimpleBuildStep
A Jenkins build step that collects Git repository information from a local workspace directory and registers it with the current build.

This step allows a build to recognize a directory as a Git repository even if the checkout was not performed by the standard Git SCM plugin during the current stage (e.g., if the repo was generated, restored from cache, or checked out by a script).

It populates BuildData actions, allowing subsequent steps to access Git revision data and optionally generating changelogs.

  • Field Details

    • LOGGER

      public static final Logger LOGGER
  • Constructor Details

    • CollectGitStep

      @DataBoundConstructor public CollectGitStep()
      Default constructor for DataBound instantiation.
  • Method Details

    • setPath

      @DataBoundSetter public void setPath(String path)
      Sets the relative path to the git directory.
      Parameters:
      path - The path relative to the workspace root.
    • getPath

      public String getPath()
      Gets the relative path to the git directory.
      Returns:
      The path, or null.
    • setChangelog

      @DataBoundSetter public void setChangelog(boolean changelog)
      Sets whether to generate a changelog.
      Parameters:
      changelog - true to enable changelog generation.
    • getChangelog

      public Boolean getChangelog()
      Gets the changelog generation flag.
      Returns:
      true if changelog generation is enabled.
    • setRemote

      @DataBoundSetter public void setRemote(String remote)
      Sets the specific remote name (origin, m, ...).
      Parameters:
      remote - Set the remote name.
    • getRemote

      public String getRemote()
      Gets the remote branch.
      Returns:
      The return the remote name.
    • setMarkedCommit

      @DataBoundSetter public void setMarkedCommit(String markedCommit)
      Sets the specific commit or branch to mark as the previous baseline.
      Parameters:
      markedCommit - A SHA1 hash or branch name (e.g., "master").
    • getMarkedCommit

      public String getMarkedCommit()
      Gets the marked commit reference.
      Returns:
      The marked commit string.
    • perform

      public void perform(@Nonnull Run<?,?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException
      Executes the build step.

      This method performs the following actions:

      1. Resolves the Git directory path.
      2. Validates that the directory is a Git repository.
      3. Scans the repository using GitScanner to retrieve remote URLs and revisions.
      4. Optionally generates a changelog if requested and differences are found.
      5. Creates a BuildData object and attaches it to the run actions.
      6. Attaches MultiScmEnvAction for environment variable contribution.
      Specified by:
      perform in interface SimpleBuildStep
      Parameters:
      run - The current build.
      workspace - The project workspace.
      launcher - The launcher.
      listener - The build listener for logging.
      Throws:
      InterruptedException - If the operation is interrupted.
      IOException - If an I/O error occurs (e.g., repo not found).