java.lang.Object
com.sysdig.jenkins.plugins.sysdig.infrastructure.jenkins.RunContext

public class RunContext extends Object
Wraps the context of a Jenkins run. A run represents the runtime execution of a Jenkins job.
  • Constructor Details

    • RunContext

      public RunContext(@Nonnull Run<?,?> run, @Nonnull FilePath workspace, @Nonnull EnvVars envVars, @Nonnull Launcher launcher, @Nonnull TaskListener listener)
      Constructs a new RunContext with the given parameters.
      Parameters:
      run - The Jenkins run.
      workspace - The workspace directory.
      envVars - The environment variables of the run execution.
      listener - The task listener for logging.
  • Method Details

    • getRun

      public Run<?,?> getRun()
      Retrieves the Jenkins run associated with this context.
      Returns:
      The Jenkins run.
    • getPathFromWorkspace

      public FilePath getPathFromWorkspace(@Nonnull String... subpaths)
      Constructs a FilePath within the workspace by appending the given subpaths.
      Parameters:
      subpaths - The subpaths to append.
      Returns:
      The resulting FilePath.
    • getEnvVars

      public EnvVars getEnvVars()
      Retrieves the environment variables of the build execution.
      Returns:
      The environment variables.
    • getLogger

      public SysdigLogger getLogger()
      Retrieves the custom Sysdig logger. Useful for consistent log reporting within the plugin.
      Returns:
      The SysdigLogger instance.
    • getSysdigTokenFromCredentials

      public String getSysdigTokenFromCredentials(@Nonnull String credID) throws AbortException
      Retrieves the Sysdig API token from Jenkins credentials using the provided credential ID.
      Parameters:
      credID - The ID of the Jenkins credential.
      Returns:
      The plain text Sysdig API token.
      Throws:
      AbortException - If the credential ID is invalid or not found.
    • perform

      public void perform(@Nonnull SimpleBuildStep buildStep) throws IOException, InterruptedException
      Executes a SimpleBuildStep within the current run context.
      Parameters:
      buildStep - The build step to perform.
      Throws:
      IOException - If an I/O error occurs during execution.
      InterruptedException - If the thread is interrupted.
    • getProjectName

      public String getProjectName()
      Retrieves the display name of the Jenkins project associated with this run.
      Returns:
      The project name.
    • getJobNumber

      public int getJobNumber()
      Retrieves the build number of the current run.
      Returns:
      The job number.
    • call

      public <V, E extends Throwable> V call(@Nonnull hudson.remoting.Callable<V,E> act) throws IOException, InterruptedException, E
      Executes a Callable task within the workspace context. This allows for remote execution in Jenkins' distributed build environment.
      Type Parameters:
      V - The return type of the Callable.
      E - The exception type that the Callable might throw.
      Parameters:
      act - The Callable task to execute.
      Returns:
      The result of the Callable execution.
      Throws:
      IOException - If an I/O error occurs during execution.
      InterruptedException - If the thread is interrupted.
      E - If the Callable throws an exception.
    • getLauncher

      public Launcher getLauncher()
      Returns a launcher that is able to perform commands either locally or remotely, based on the context of the run.
      Returns:
      The launcher to perform commands.