Class CommandLineBuildService
- java.lang.Object
-
- jetbrains.buildServer.agent.runner.CommandLineBuildService
-
- Direct Known Subclasses:
BuildServiceAdapter
@UserImplemented(adapterClass=BuildServiceAdapter.class) public abstract class CommandLineBuildService extends Object
Represents process run parameters that- checks processes exit code regarding
AgentRunningBuild.getFailBuildOnExitCode()
build configuration option - kill all agent child processes on build interrupt
- returns
LoggingProcessListener
to log all process output to the build log
BuildServiceAdapter
to simplify code.- Since:
- 4.0
- Author:
- Eugene.Petrenko
-
-
Constructor Summary
Constructors Constructor Description CommandLineBuildService()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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, meaninggetRunResult(int)
returnedBuildFinishedStatus.FINISHED_SUCCESS
Not called in case of build interruption.void
beforeProcessStarted()
this method is called before creation commandline preparation startedstatic BuildProblemData
createExitCodeBuildProblem(int exitCode, String runType, String processFlowId)
Deprecated.since 2018.1.1: useExitCodeProblemBuilder
insteadprotected AgentRunningBuild
getBuild()
FlowLogger
getFlowLogger()
List<ProcessListener>
getListeners()
Build process event listenersBuildProgressLogger
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()
-
-
-
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 agentrunner
- 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 alterBuildFinishedStatus
. If you need changingBuildFinishedStatus
consider usinggetRunResult(int)
method instead. This method is called strictly beforegetRunResult(int)
- Throws:
RunBuildException
- to break the build
-
afterProcessSuccessfullyFinished
public void afterProcessSuccessfullyFinished() throws RunBuildException
this method is called after process has successfully finished, meaninggetRunResult(int)
returnedBuildFinishedStatus.FINISHED_SUCCESS
Not called in case of build interruption. NOTE: The result of this method depends onAgentRunningBuild.getFailBuildOnExitCode()
, if you need more predictable behaviour, override this method. This is a good place to run any post-build activity the does not alterBuildFinishedStatus
and that should only be started if the build succeeded. If you need changingBuildFinishedStatus
consider usinggetRunResult(int)
method instead. This method is called strictly beforegetRunResult(int)
andafterProcessFinished()
- 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 List<ProcessListener> getListeners()
Build process event listeners To log all process output to the build log consider usingLoggingProcessListener
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 someBuildFinishedStatus
. If you do not need changingBuildFinishedStatus
consider usingafterProcessFinished()
method instead. This method is called strictly afterafterProcessFinished()
NOTE: The result of this method depends onAgentRunningBuild.getFailBuildOnExitCode()
, if you need more predictable behaviour, override this method.- Parameters:
exitCode
- started process exit code- Returns:
- final build status
-
createExitCodeBuildProblem
@NotNull @Deprecated public static BuildProblemData createExitCodeBuildProblem(int exitCode, @NotNull String runType, @Nullable String processFlowId)
Deprecated.since 2018.1.1: useExitCodeProblemBuilder
instead
-
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 public final BuildProgressLogger getLogger()
- Returns:
- current running build progress logger
-
getFlowLogger
@NotNull public final FlowLogger getFlowLogger()
-
-