jetbrains.buildServer.agent.runner
Class CommandLineBuildService

java.lang.Object
  extended by jetbrains.buildServer.agent.runner.CommandLineBuildService
Direct Known Subclasses:
BuildServiceAdapter

@UserImplemented(adapterClass=BuildServiceAdapter.class)
public abstract class CommandLineBuildService
extends java.lang.Object

Represents process run parameters that

Use BuildServiceAdapter to simplify code.

Since:
4.0
Author:
Eugene.Petrenko

Constructor Summary
CommandLineBuildService()
           
 
Method Summary
 void afterInitialized()
          called after the service is initialized and all necessary dependencies are injected.
 void afterProcessFinished()
          this method is called after process finished and before getRunResult called.
 void afterProcessSuccessfullyFinished()
          this method is called after process has successfully finished, meaning getRunResult(int) returned BuildFinishedStatus.FINISHED_SUCCESS Not called in case of build interruption.
 void beforeProcessStarted()
          this method is called before creation commandline preparation started
static BuildProblemData createExitCodeBuildProblem(int exitCode, java.lang.String runType)
           
protected  AgentRunningBuild getBuild()
           
 java.util.List<ProcessListener> getListeners()
          Build process event listeners

To log all process output to the build log consider using LoggingProcessListener

To log only latest lines from class

protected  BuildProgressLogger getLogger()
           
protected  BuildRunnerContext getRunnerContext()
           
 BuildFinishedStatus getRunResult(int exitCode)
          This method is called if process was not interrupted by build agent.
 void initialize(AgentRunningBuild build, BuildRunnerContext runner)
          Makes the second phase of initialization.
 TerminationAction interrupt()
          called only if build is about to be interrupted by TeamCity.
 boolean isCommandLineLoggingEnabled()
           
protected  void logBuildProblem(BuildProblemData buildProblem)
           
abstract  ProgramCommandLine makeProgramCommandLine()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineBuildService

public CommandLineBuildService()
Method Detail

initialize

public final void initialize(@NotNull
                             AgentRunningBuild build,
                             @NotNull
                             BuildRunnerContext runner)
                      throws RunBuildException
Makes the second phase of initialization. Called by TeamCity. Derived classes should not call or override this method. The signature of this method may change in the future versions.

Parameters:
build - build on agent
runner - runner context containing actual parameters for the run
Throws:
RunBuildException - to break the build

afterInitialized

public void afterInitialized()
                      throws RunBuildException
called after the service is initialized and all necessary dependencies are injected. Derived classes should not perform any significant activities or use TeamCity infrastructure until initialization is completed and this method is called.

Throws:
RunBuildException - to break the build

beforeProcessStarted

public void beforeProcessStarted()
                          throws RunBuildException
this method is called before creation commandline preparation started

Throws:
RunBuildException - to break the build

afterProcessFinished

public void afterProcessFinished()
                          throws RunBuildException
this method is called after process finished and before getRunResult called. Not called in case of build interruption This is a good place to run any post-build activity the does not alter BuildFinishedStatus. If you need changing BuildFinishedStatus consider using getRunResult(int) method instead. This method is called strictly before getRunResult(int)

Throws:
RunBuildException - to break the build

afterProcessSuccessfullyFinished

public void afterProcessSuccessfullyFinished()
                                      throws RunBuildException
this method is called after process has successfully finished, meaning getRunResult(int) returned BuildFinishedStatus.FINISHED_SUCCESS Not called in case of build interruption. NOTE: The result of this method depends on AgentRunningBuild.getFailBuildOnExitCode(), if you need more predictable behaviour, override this method. This is a good place to run any post-build activity the does not alter BuildFinishedStatus and that should only be started if the build succeeded. If you need changing BuildFinishedStatus consider using getRunResult(int) method instead. This method is called strictly before getRunResult(int) and afterProcessFinished()

Throws:
RunBuildException - to break the build

makeProgramCommandLine

@NotNull
public abstract ProgramCommandLine makeProgramCommandLine()
                                                   throws RunBuildException
Returns:
generated commandline for the process to start
Throws:
RunBuildException - to break the build

getListeners

@NotNull
public java.util.List<ProcessListener> getListeners()
Build process event listeners

To log all process output to the build log consider using LoggingProcessListener

To log only latest lines from class

Returns:
build process event listener if needed

interrupt

@NotNull
public TerminationAction interrupt()
called only if build is about to be interrupted by TeamCity.

Returns:
the way to stop the process on interruption event

getRunResult

@NotNull
public BuildFinishedStatus getRunResult(int exitCode)
This method is called if process was not interrupted by build agent. In case build was interrupted, that method may not be called. NOTE. If a build is not interrupted this method is called only once. If a build is interrupted, this method is not called at all. This is a good place to run any post-build activity the computes some BuildFinishedStatus. If you do not need changing BuildFinishedStatus consider using afterProcessFinished() method instead. This method is called strictly after afterProcessFinished() NOTE: The result of this method depends on AgentRunningBuild.getFailBuildOnExitCode(), if you need more predictable behaviour, override this method.

Parameters:
exitCode - started process exit code
Returns:
final build status

createExitCodeBuildProblem

@NotNull
public static BuildProblemData createExitCodeBuildProblem(int exitCode,
                                                                  @NotNull
                                                                  java.lang.String runType)

logBuildProblem

protected final void logBuildProblem(BuildProblemData buildProblem)

isCommandLineLoggingEnabled

public boolean isCommandLineLoggingEnabled()
Returns:
if true, TeamCity will print the full command line string into the build log. True by default.

getBuild

@NotNull
protected final AgentRunningBuild getBuild()
Returns:
current AgentRunningBuild instance

getRunnerContext

@NotNull
protected final BuildRunnerContext getRunnerContext()
Returns:
current BuildRunnerContext instance associated with build

getLogger

@NotNull
protected final BuildProgressLogger getLogger()
Returns:
current running build progress logger