Class RunContext
java.lang.Object
com.sysdig.jenkins.plugins.sysdig.infrastructure.jenkins.RunContext
Wraps the context of a Jenkins run.
A run represents the runtime execution of a Jenkins job.
-
Constructor Summary
ConstructorDescriptionRunContext
(Run<?, ?> run, FilePath workspace, EnvVars envVars, Launcher launcher, TaskListener listener) Constructs a new RunContext with the given parameters. -
Method Summary
Modifier and TypeMethodDescription<V,
E extends Throwable>
Vcall
(hudson.remoting.Callable<V, E> act) Executes a Callable task within the workspace context.Retrieves the environment variables of the build execution.int
Retrieves the build number of the current run.Returns a launcher that is able to perform commands either locally or remotely, based on the context of the run.Retrieves the custom Sysdig logger.getPathFromWorkspace
(String... subpaths) Constructs a FilePath within the workspace by appending the given subpaths.Retrieves the display name of the Jenkins project associated with this run.Run<?,
?> getRun()
Retrieves the Jenkins run associated with this context.getSysdigTokenFromCredentials
(String credID) Retrieves the Sysdig API token from Jenkins credentials using the provided credential ID.void
perform
(SimpleBuildStep buildStep) Executes a SimpleBuildStep within the current run context.
-
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
Retrieves the Jenkins run associated with this context.- Returns:
- The Jenkins run.
-
getPathFromWorkspace
Constructs a FilePath within the workspace by appending the given subpaths.- Parameters:
subpaths
- The subpaths to append.- Returns:
- The resulting FilePath.
-
getEnvVars
Retrieves the environment variables of the build execution.- Returns:
- The environment variables.
-
getLogger
Retrieves the custom Sysdig logger. Useful for consistent log reporting within the plugin.- Returns:
- The SysdigLogger instance.
-
getSysdigTokenFromCredentials
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
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
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, EExecutes 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
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.
-