Class RunSelectorContext

java.lang.Object
org.jenkinsci.plugins.runselector.context.RunSelectorContext
All Implemented Interfaces:
Cloneable

public class RunSelectorContext extends Object implements Cloneable
Context for an execution of runselector. This allows us to adding new fields without affecting existing plugins.

You can manage plugin specific information using addExtension(Object) and getExtension(Class).

  • Constructor Details

  • Method Details

    • getJenkins

      @NonNull public Jenkins getJenkins()
      Returns:
      the Jenkins instance
    • getBuild

      @NonNull public Run<?,?> getBuild()
      Returns:
      the build running runselector
    • getListener

      @NonNull public TaskListener getListener()
      Returns:
      the listener for the build running runselector
    • getEnvVars

      @NonNull public EnvVars getEnvVars()
      Returns:
      environment variables for the current build
    • getConsole

      @NonNull public PrintStream getConsole()
      Shortcut for getListener().getLogger()
      Returns:
      stream to output logs
    • setVerbose

      public void setVerbose(boolean verbose)
      Parameters:
      verbose - whether output verbose (for diagnostics) logs
    • isVerbose

      public boolean isVerbose()
      Returns:
      whether output verbose (for diagnostics) logs
    • setRunFilter

      public void setRunFilter(@NonNull RunFilter runFilter)
      Parameters:
      runFilter - the filter for builds
    • getRunFilter

      @NonNull public RunFilter getRunFilter()
      Returns:
      a filter for builds
    • setLastMatchBuild

      public void setLastMatchBuild(Run<?,?> lastMatchBuild)
      Parameters:
      lastMatchBuild - build picked at the last time
    • getLastMatchBuild

      @CheckForNull public Run<?,?> getLastMatchBuild()
      The build picked at the last time (but not matched with the filter). RunSelectors should continue the enumeration from this.
      Returns:
      build picked at the last time
    • getExtensionList

      @NonNull public List<Object> getExtensionList()
      Returns:
      additional information by plugins
    • addExtension

      public void addExtension(@NonNull Object extension)
      Add an object to hold plugin specific information.
      Parameters:
      extension - extension object
    • removeExtension

      public boolean removeExtension(@NonNull Object extension)
      Parameters:
      extension - extension object to remove
      Returns:
      true if the extension is contained
    • replaceExtension

      public boolean replaceExtension(@NonNull Object extension)
      Removes extensions with the same class type before adding.
      Parameters:
      extension - extension object to replace with
      Returns:
      true if an extension object of the same class class is contained
    • getExtension

      @CheckForNull public <T> T getExtension(@NonNull Class<T> clazz)
      Extract an extension object of the specified class.
      Type Parameters:
      T - specified with clazz
      Parameters:
      clazz - class of the extension to extract
      Returns:
      extension of the class
    • logInfo

      public void logInfo(@NonNull String message)
      Outputs a log message
      Parameters:
      message - message to log
    • logInfo

      public void logInfo(@NonNull String pattern, Object... arguments)
      Outputs a log message in MessageFormat formats.
      Parameters:
      pattern - pattern for MessageFormat
      arguments - values to format
    • logDebug

      public void logDebug(@NonNull String message)
      Outputs a log message if isVerbose() is true
      Parameters:
      message - message to log
    • logDebug

      public void logDebug(@NonNull String pattern, Object... arguments)
      Outputs a log message in MessageFormat formats if isVerbose() is true
      Parameters:
      pattern - pattern for MessageFormat
      arguments - values to format
    • logException

      public void logException(@NonNull String string, @NonNull Throwable t)
      Outputs a log message with an exception
      Parameters:
      string - message to log
      t - exception to log
    • clone

      public RunSelectorContext clone()
      Overrides:
      clone in class Object