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
LoggingProcessListenerto log all process output to the build log
BuildServiceAdapterto 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 voidafterInitialized()called after the service is initialized and all necessary dependencies are injected.voidafterProcessFinished()this method is called after process finished and before getRunResult called.voidafterProcessSuccessfullyFinished()this method is called after process has successfully finished, meaninggetRunResult(int)returnedBuildFinishedStatus.FINISHED_SUCCESSNot called in case of build interruption.voidbeforeProcessStarted()this method is called before creation commandline preparation startedstatic BuildProblemDatacreateExitCodeBuildProblem(int exitCode, String runType, String processFlowId)Deprecated.since 2018.1.1: useExitCodeProblemBuilderinsteadprotected AgentRunningBuildgetBuild()FlowLoggergetFlowLogger()List<ProcessListener>getListeners()Build process event listenersBuildProgressLoggergetLogger()protected BuildRunnerContextgetRunnerContext()BuildFinishedStatusgetRunResult(int exitCode)This method is called if process was not interrupted by build agent.voidinitialize(AgentRunningBuild build, BuildRunnerContext runner)Makes the second phase of initialization.TerminationActioninterrupt()called only if build is about to be interrupted by TeamCity.booleanisCommandLineLoggingEnabled()protected voidlogBuildProblem(BuildProblemData buildProblem)abstract ProgramCommandLinemakeProgramCommandLine()
-
-
-
Method Detail
-
initialize
public final void initialize(@NotNull AgentRunningBuild build, @NotNull BuildRunnerContext runner) throws RunBuildExceptionMakes 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 RunBuildExceptioncalled 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 RunBuildExceptionthis method is called before creation commandline preparation started- Throws:
RunBuildException- to break the build
-
afterProcessFinished
public void afterProcessFinished() throws RunBuildExceptionthis 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 changingBuildFinishedStatusconsider usinggetRunResult(int)method instead. This method is called strictly beforegetRunResult(int)- Throws:
RunBuildException- to break the build
-
afterProcessSuccessfullyFinished
public void afterProcessSuccessfullyFinished() throws RunBuildExceptionthis method is called after process has successfully finished, meaninggetRunResult(int)returnedBuildFinishedStatus.FINISHED_SUCCESSNot 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 alterBuildFinishedStatusand that should only be started if the build succeeded. If you need changingBuildFinishedStatusconsider 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 usingLoggingProcessListenerTo 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 changingBuildFinishedStatusconsider 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: useExitCodeProblemBuilderinstead
-
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()
-
-