Package jetbrains.buildServer.agent.impl
Class AgentRunningBuildImpl
- java.lang.Object
-
- jetbrains.buildServer.agent.impl.AgentBuildSettingsProxy<AgentBuildSettingsEx>
-
- jetbrains.buildServer.agent.impl.AgentRunningBuildImpl
-
- All Implemented Interfaces:
AgentBuildSettings
,AgentRunningBuild
,AgentRunningBuildEx
,Loggable
public class AgentRunningBuildImpl extends AgentBuildSettingsProxy<AgentBuildSettingsEx> implements AgentRunningBuildEx
-
-
Constructor Summary
Constructors Constructor Description AgentRunningBuildImpl(AgentBuildSettingsEx agentBuildSettings, DirectoryMapDirtyTracker dirty, AgentRevisionManager revisionManager, BuildLogTail buildLogTail, BuildContextEx buildContext, BuildRunnerContextFactory runnerContextFactory, AgentLogListener agentLogListener, RunningBuildServiceLocator buildSpringContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSharedConfigParameter(String key, String value)
Adds build wide configuration parameter.void
addSharedEnvironmentVariable(String key, String value)
Adds build wide environment variable.void
addSharedSystemProperty(String key, String value)
Adds build wide system property.boolean
cleanCheckoutEnforced()
Indicates whether clean checkout was enforced for a build in designated directoryvoid
cleanParameters()
void
clearCheckoutDirRevisions()
Deletes information about checkout directory revisions preparing directory for clean checkout.String
describe(boolean verbose)
String
getArtifactsPaths()
Returns artifacts paths specified for build.Map<String,String>
getArtifactStorageSettings()
BuildContextEx
getBuildContext()
Collection<AgentBuildFeature>
getBuildFeatures()
Collection<AgentBuildFeature>
getBuildFeaturesOfType(String type)
BuildLogTail
getBuildLogTail()
String
getBuildNumber()
Returns current build number.BuildParametersMap
getBuildParameters()
Returns build parameters with all references expandedFile
getCheckoutDirectory()
Build state partAgentCheckoutDirRevisionInfo
getCheckoutDirRevisionInfo()
BuildRunnerContextEx
getCurrentRunnerContext()
AgentCheckoutMode
getEffectiveCheckoutMode()
Get checkout mode that is used for this build.boolean
getFailBuildOnExitCode()
Property is defined by build configuration settings to define the way build runner should process build process exit code.FullCheckoutFlag
getFullCheckoutFlag()
BuildInterruptDetails
getInterruptDetails()
BuildInterruptReason
getInterruptReason()
Use this method to check if build is interrupted.NodeIdHolder
getNodeIdHolder()
ControlDescription
getParameterControlDescription(String name)
Returns description object for the corresponding parameter if it is known on the agent.String
getParameterSpec(String name)
PasswordReplacer
getPasswordReplacer()
<T> T
getPerBuildService(Class<T> clazz)
Service locator for per-build componentsMap<String,String>
getRunnerParameters()
Returns unmodifiable map of runner parameters with all references expandedList<BuildRunnerSettings>
getRunnersToExecute()
BuildParametersMap
getSharedBuildParameters()
Returns build parameters.Map<String,String>
getSharedConfigParameters()
Returns configuration parameters of this build If you haveBuildRunnerContext
, consider usingBuildRunnerContext.getConfigParameters()
ValueResolver
getSharedParametersResolver()
Creates value resolver for parameters resolution in strings.Map<String,String>
getUnresolvedServerParameters()
Return a map of all parameters which came from the TeamCity serverString
getVcsSettingsHash()
Returns hash of all vcs instance settings.File
getWorkingDirectory()
Returns build working directory: working directory where build runner startedvoid
interruptBuild(String comment, boolean reQueue)
Interrupt and cancel running build.boolean
isBuildFailingOnServer()
Make synchronous call to the build server and check if the build is failing thereboolean
isCheckoutDirDirty()
Returns the "dirty" status of the checkout directory.boolean
isDetachedFromAgent()
Return detached status of the agent.boolean
isInAlwaysExecutingStage()
boolean
isPreparationDone()
boolean
relyOnVcsToRestoreFromErrors()
void
selectRunnerState(BuildRunnerSettings runner)
void
setBuildRunnerToExecute(int buildRunnerToExecute)
Sets the number of runner to execute a build step (used for purposes of Executor Mode)void
setCheckoutDirDirty(boolean checkoutDirDirty)
Depending oncheckoutDirDirty
value, marks checkout directory as either clean or dirty, both on agent and on server.void
setDefaultCheckoutDirectory(AgentCheckoutMode checkoutMode)
Set default checkout directory based on checkout mode that will be used in this build.void
setDetachedFromAgent(boolean detached)
Make the agent be detacheced/attached to some build.void
setInAlwaysExecutingStage(boolean inAlwaysExecutingStage)
void
setPreparationDone()
void
setResolvedCheckoutMode(AgentCheckoutMode resolvedCheckoutMode)
Set checkout method that will be used in this build.void
stopBuild(String message)
Terminates execution of the build at the current build stage.String
toString()
void
updateBuildNumber(String newBuildNumber)
-
Methods inherited from class jetbrains.buildServer.agent.impl.AgentBuildSettingsProxy
getAccessCode, getAccessUser, getAgentConfiguration, getAgentTempDirectory, getArtifactDependencies, getBuildCurrentVersion, getBuildId, getBuildLogger, getBuildPreviousVersion, getBuildRunners, getBuildTempDirectory, getBuildTypeExternalId, getBuildTypeId, getBuildTypeName, getBuildTypeOptionValue, getCheckoutType, getDefaultCheckoutDirectory, getExecutionTimeoutMinutes, getHost, getPersonalVcsChanges, getProjectName, getVcsChanges, getVcsRootEntries, getVcsSettingsHashForCheckoutMode, isCheckoutOnAgent, isCheckoutOnServer, isCleanBuild, isCustomCheckoutDirectory, isPersonal, isPersonalPatchAvailable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.agent.AgentBuildSettings
getAccessCode, getAccessUser, getAgentConfiguration, getAgentTempDirectory, getArtifactDependencies, getBuildCurrentVersion, getBuildId, getBuildLogger, getBuildPreviousVersion, getBuildRunners, getBuildTempDirectory, getBuildTypeExternalId, getBuildTypeId, getBuildTypeName, getBuildTypeOptionValue, getCheckoutType, getDefaultCheckoutDirectory, getExecutionTimeoutMinutes, getPersonalVcsChanges, getProjectName, getVcsChanges, getVcsRootEntries, getVcsSettingsHashForCheckoutMode, isCheckoutOnAgent, isCheckoutOnServer, isCleanBuild, isCustomCheckoutDirectory, isPersonal, isPersonalPatchAvailable
-
-
-
-
Constructor Detail
-
AgentRunningBuildImpl
public AgentRunningBuildImpl(@NotNull AgentBuildSettingsEx agentBuildSettings, @NotNull DirectoryMapDirtyTracker dirty, @NotNull AgentRevisionManager revisionManager, @NotNull BuildLogTail buildLogTail, @NotNull BuildContextEx buildContext, @NotNull BuildRunnerContextFactory runnerContextFactory, @NotNull AgentLogListener agentLogListener, @NotNull RunningBuildServiceLocator buildSpringContext)
-
-
Method Detail
-
getInterruptDetails
@Nullable public BuildInterruptDetails getInterruptDetails()
- Specified by:
getInterruptDetails
in interfaceAgentRunningBuildEx
- Returns:
- Detailed information about build interruption (if the build was interrupted)
-
setDetachedFromAgent
public void setDetachedFromAgent(boolean detached)
Description copied from interface:AgentRunningBuildEx
Make the agent be detacheced/attached to some build. Detached indicates that the build tasks are finished on the agent but the build itself should continue until some external process finishes it- Specified by:
setDetachedFromAgent
in interfaceAgentRunningBuildEx
- Parameters:
detached
- true if agent should be detached from its current build
-
isDetachedFromAgent
public boolean isDetachedFromAgent()
Description copied from interface:AgentRunningBuildEx
Return detached status of the agent.- Specified by:
isDetachedFromAgent
in interfaceAgentRunningBuildEx
- Returns:
- true if the agent is detached from a build; false - otherwise
-
getInterruptReason
@Nullable public BuildInterruptReason getInterruptReason()
Description copied from interface:AgentRunningBuild
Use this method to check if build is interrupted.- Specified by:
getInterruptReason
in interfaceAgentRunningBuild
- Returns:
- current build interrupt reason or null if build is not interrupted
-
getFullCheckoutFlag
@NotNull public FullCheckoutFlag getFullCheckoutFlag()
- Specified by:
getFullCheckoutFlag
in interfaceAgentRunningBuildEx
-
relyOnVcsToRestoreFromErrors
public boolean relyOnVcsToRestoreFromErrors()
- Specified by:
relyOnVcsToRestoreFromErrors
in interfaceAgentRunningBuildEx
- Returns:
- true if agent-side checkout is used and an option to rely on VCS to restore from errors is set
-
getUnresolvedServerParameters
public Map<String,String> getUnresolvedServerParameters()
Description copied from interface:AgentRunningBuildEx
Return a map of all parameters which came from the TeamCity server- Specified by:
getUnresolvedServerParameters
in interfaceAgentRunningBuildEx
- Returns:
- see above
-
getBuildParameters
@NotNull public BuildParametersMap getBuildParameters()
Description copied from interface:AgentRunningBuild
Returns build parameters with all references expanded- Specified by:
getBuildParameters
in interfaceAgentRunningBuild
- Returns:
- see above
-
stopBuild
public void stopBuild(@NotNull String message)
Description copied from interface:AgentRunningBuild
Terminates execution of the build at the current build stage. Build will be stopped with error and given reason. Build will not be marked as canceled.AgentLifeCycleListener.beforeBuildInterrupted(AgentRunningBuild, BuildInterruptReason)
event will be fired.- Specified by:
stopBuild
in interfaceAgentRunningBuild
- Parameters:
message
- build stop reason
-
cleanParameters
public void cleanParameters()
- Specified by:
cleanParameters
in interfaceAgentRunningBuildEx
-
setBuildRunnerToExecute
public void setBuildRunnerToExecute(int buildRunnerToExecute)
Description copied from interface:AgentRunningBuildEx
Sets the number of runner to execute a build step (used for purposes of Executor Mode)- Specified by:
setBuildRunnerToExecute
in interfaceAgentRunningBuildEx
- Parameters:
buildRunnerToExecute
- number of runner to be a build step executor
-
getRunnersToExecute
@NotNull public List<BuildRunnerSettings> getRunnersToExecute()
- Specified by:
getRunnersToExecute
in interfaceAgentRunningBuildEx
- Returns:
-
getNodeIdHolder
@NotNull public NodeIdHolder getNodeIdHolder()
- Specified by:
getNodeIdHolder
in interfaceAgentRunningBuild
- Returns:
- information about the current node id associated with this build, can be used to set a proper NodeId cookie to HTTP requests to TeamCity server to ensure the request is landed on a specified node
-
interruptBuild
public void interruptBuild(@NotNull String comment, boolean reQueue)
Description copied from interface:AgentRunningBuild
Interrupt and cancel running build.- Specified by:
interruptBuild
in interfaceAgentRunningBuild
- Parameters:
comment
- will be used as a canceling comment for the buildreQueue
- if true, build should be re-queued on the server side
-
getRunnerParameters
@NotNull public Map<String,String> getRunnerParameters()
Description copied from interface:AgentRunningBuild
Returns unmodifiable map of runner parameters with all references expanded- Specified by:
getRunnerParameters
in interfaceAgentRunningBuild
- Returns:
- see above
-
getFailBuildOnExitCode
public boolean getFailBuildOnExitCode()
Description copied from interface:AgentRunningBuild
Property is defined by build configuration settings to define the way build runner should process build process exit code.- Specified by:
getFailBuildOnExitCode
in interfaceAgentRunningBuild
- Returns:
- true if build runner is expected to fail build if build process returned non-zero exit code
-
isInAlwaysExecutingStage
public boolean isInAlwaysExecutingStage()
- Specified by:
isInAlwaysExecutingStage
in interfaceAgentRunningBuild
- Returns:
- true if the currently executing build stage is "Always executing stage"
- See Also:
ServerProvidedProperties.BUILD_STEP_EXECUTION_MODE_ALWAYS
-
setInAlwaysExecutingStage
public void setInAlwaysExecutingStage(boolean inAlwaysExecutingStage)
- Specified by:
setInAlwaysExecutingStage
in interfaceAgentRunningBuildEx
-
getBuildNumber
@NotNull public String getBuildNumber()
Description copied from interface:AgentRunningBuild
Returns current build number. Note that during the build, build number may change (i.e. build script can emit ##teamcity[buildNumber ''] service message. Because of this, it is safer to read build number before build is finished (when build process is not working anymore).- Specified by:
getBuildNumber
in interfaceAgentRunningBuild
- Returns:
- current build number
-
getWorkingDirectory
@NotNull public File getWorkingDirectory()
Description copied from interface:AgentRunningBuild
Returns build working directory: working directory where build runner started- Specified by:
getWorkingDirectory
in interfaceAgentRunningBuild
- Returns:
- see above
-
updateBuildNumber
public void updateBuildNumber(@NotNull String newBuildNumber)
- Specified by:
updateBuildNumber
in interfaceAgentRunningBuildEx
-
setPreparationDone
public void setPreparationDone()
- Specified by:
setPreparationDone
in interfaceAgentRunningBuildEx
-
isPreparationDone
public boolean isPreparationDone()
- Specified by:
isPreparationDone
in interfaceAgentRunningBuildEx
-
getCheckoutDirectory
@NotNull public File getCheckoutDirectory()
Build state part- Specified by:
getCheckoutDirectory
in interfaceAgentRunningBuild
- Returns:
- see above
-
getEffectiveCheckoutMode
@Nullable public AgentCheckoutMode getEffectiveCheckoutMode()
Description copied from interface:AgentRunningBuild
Get checkout mode that is used for this build. Returns null if checkout mode was not calculated yet. This method differs from theAgentBuildSettings.getCheckoutType()
as it resolvesAgentBuild.CheckoutType.AUTO
to the server or agent-side checkout.- Specified by:
getEffectiveCheckoutMode
in interfaceAgentRunningBuild
-
setResolvedCheckoutMode
public void setResolvedCheckoutMode(@NotNull AgentCheckoutMode resolvedCheckoutMode)
Description copied from interface:AgentRunningBuildEx
Set checkout method that will be used in this build.- Specified by:
setResolvedCheckoutMode
in interfaceAgentRunningBuildEx
- See Also:
AgentRunningBuild.getEffectiveCheckoutMode()
-
setDefaultCheckoutDirectory
public void setDefaultCheckoutDirectory(@NotNull AgentCheckoutMode checkoutMode)
Description copied from interface:AgentRunningBuildEx
Set default checkout directory based on checkout mode that will be used in this build.- Specified by:
setDefaultCheckoutDirectory
in interfaceAgentRunningBuildEx
-
getArtifactsPaths
public String getArtifactsPaths()
Description copied from interface:AgentRunningBuild
Returns artifacts paths specified for build. This value is always resolved in runtime- Specified by:
getArtifactsPaths
in interfaceAgentRunningBuild
- Returns:
- artifacts paths
-
getArtifactStorageSettings
@NotNull public Map<String,String> getArtifactStorageSettings()
- Specified by:
getArtifactStorageSettings
in interfaceAgentRunningBuild
- Returns:
- artifact storage settings if there are any available for this build
-
addSharedConfigParameter
public void addSharedConfigParameter(@NotNull String key, @NotNull String value)
Description copied from interface:AgentRunningBuild
Adds build wide configuration parameter. Modifications will be available in all build runner states. If you haveBuildRunnerContext
, consider usingBuildRunnerContext.addConfigParameter(String, String)
*- Specified by:
addSharedConfigParameter
in interfaceAgentRunningBuild
- Parameters:
key
- namevalue
- value- See Also:
BuildRunnerContext.addConfigParameter(String, String)
-
addSharedSystemProperty
public void addSharedSystemProperty(@NotNull String key, @NotNull String value)
Description copied from interface:AgentRunningBuild
Adds build wide system property. Creates build parameters withConstants.SYSTEM_PREFIX
prefix Modifications will be available in all build runner states. If you haveBuildRunnerContext
, consider usingBuildRunnerContext.addSystemProperty(String, String)
- Specified by:
addSharedSystemProperty
in interfaceAgentRunningBuild
- Parameters:
key
- property namevalue
- property value- See Also:
BuildRunnerContext.addSystemProperty(String, String)
-
addSharedEnvironmentVariable
public void addSharedEnvironmentVariable(@NotNull String key, @NotNull String value)
Description copied from interface:AgentRunningBuild
Adds build wide environment variable. Creates build parameters withConstants.ENV_PREFIX
prefix Note, on Windows machines environment size can be limited. Modifications will be available in all build runner states. If you haveBuildRunnerContext
, consider usingBuildRunnerContext.addEnvironmentVariable(String, String)
- Specified by:
addSharedEnvironmentVariable
in interfaceAgentRunningBuild
- Parameters:
key
- name may be case sensitive or not depending on OSvalue
- value environment variable value- See Also:
BuildRunnerContext.addEnvironmentVariable(String, String)
-
getSharedBuildParameters
@NotNull public BuildParametersMap getSharedBuildParameters()
Description copied from interface:AgentRunningBuild
Returns build parameters. Some of values may not be fully resolved. If you haveBuildRunnerContext
, consider usingBuildRunnerContext.getBuildParameters()
- Specified by:
getSharedBuildParameters
in interfaceAgentRunningBuild
- Returns:
- build-wide build parameters
- See Also:
BuildRunnerContext.getBuildParameters()
-
getSharedConfigParameters
@NotNull public Map<String,String> getSharedConfigParameters()
Description copied from interface:AgentRunningBuild
Returns configuration parameters of this build If you haveBuildRunnerContext
, consider usingBuildRunnerContext.getConfigParameters()
- Specified by:
getSharedConfigParameters
in interfaceAgentRunningBuild
- Returns:
- unmodifiable configuration parameters map
- See Also:
BuildRunnerContext.getConfigParameters()
-
getSharedParametersResolver
@NotNull public ValueResolver getSharedParametersResolver()
Description copied from interface:AgentRunningBuild
Creates value resolver for parameters resolution in strings. The resolution rules are the same as for build parameters- Specified by:
getSharedParametersResolver
in interfaceAgentRunningBuild
- Returns:
- value resolver to perform resolution of all parameters references within string
-
getBuildFeatures
@NotNull public Collection<AgentBuildFeature> getBuildFeatures()
- Specified by:
getBuildFeatures
in interfaceAgentRunningBuild
- Returns:
- collection of enabled build features for the build
-
getBuildFeaturesOfType
@NotNull public Collection<AgentBuildFeature> getBuildFeaturesOfType(@NotNull String type)
- Specified by:
getBuildFeaturesOfType
in interfaceAgentRunningBuild
- Parameters:
type
- type to filter features- Returns:
- collection of enabled build features for the build
-
getCheckoutDirRevisionInfo
@NotNull public AgentCheckoutDirRevisionInfo getCheckoutDirRevisionInfo()
- Specified by:
getCheckoutDirRevisionInfo
in interfaceAgentRunningBuildEx
- Returns:
- build checkout directory revision information
-
getBuildLogTail
@NotNull public BuildLogTail getBuildLogTail()
- Specified by:
getBuildLogTail
in interfaceAgentRunningBuildEx
- Returns:
- build log tail for this build
-
getParameterSpec
@Nullable public String getParameterSpec(@NotNull String name)
- Specified by:
getParameterSpec
in interfaceAgentRunningBuildEx
- Returns:
-
getParameterControlDescription
@Nullable public ControlDescription getParameterControlDescription(@NotNull String name)
Description copied from interface:AgentRunningBuildEx
Returns description object for the corresponding parameter if it is known on the agent.- Specified by:
getParameterControlDescription
in interfaceAgentRunningBuildEx
- Parameters:
name
- parameter name- Returns:
- control description object which is created from the parameter spec
-
getPasswordReplacer
@NotNull public PasswordReplacer getPasswordReplacer()
- Specified by:
getPasswordReplacer
in interfaceAgentRunningBuild
- Returns:
- instance of PasswordReplacer which can be used to replace passwords known to current build in different logs or files
-
isBuildFailingOnServer
public boolean isBuildFailingOnServer() throws InterruptedException
Description copied from interface:AgentRunningBuild
Make synchronous call to the build server and check if the build is failing there- Specified by:
isBuildFailingOnServer
in interfaceAgentRunningBuild
- Returns:
- true if the build is failing on server
- Throws:
InterruptedException
- if the request cannot be completed (for instance, the build is no longer present on the server)
-
getCurrentRunnerContext
@NotNull public BuildRunnerContextEx getCurrentRunnerContext()
- Specified by:
getCurrentRunnerContext
in interfaceAgentRunningBuildEx
- Returns:
- build context. This context is shared between all build runners
BuildRunnerContext
of the build. You may use this context to read/write build-wide parameters. Every time this method returns same object reference.BuildRunnerContext
interface may be used to update parameters for one build runner. - See Also:
BuildRunnerContext
-
getBuildContext
@NotNull public BuildContextEx getBuildContext()
- Specified by:
getBuildContext
in interfaceAgentRunningBuildEx
-
getPerBuildService
@Nullable public <T> T getPerBuildService(Class<T> clazz)
Description copied from interface:AgentRunningBuildEx
Service locator for per-build components- Specified by:
getPerBuildService
in interfaceAgentRunningBuildEx
- Type Parameters:
T
- type if instance- Parameters:
clazz
- class of component to return- Returns:
- per-build component instance
-
getVcsSettingsHash
@NotNull public String getVcsSettingsHash()
Description copied from interface:AgentRunningBuildEx
Returns hash of all vcs instance settings. Required to determine on agent side whether vcs settings were changed or not.- Specified by:
getVcsSettingsHash
in interfaceAgentRunningBuildEx
- Returns:
- hash of all vcs settings.
-
cleanCheckoutEnforced
public boolean cleanCheckoutEnforced()
Description copied from interface:AgentRunningBuildEx
Indicates whether clean checkout was enforced for a build in designated directory- Specified by:
cleanCheckoutEnforced
in interfaceAgentRunningBuildEx
- Returns:
- true if we should do a clean checkout
-
selectRunnerState
public void selectRunnerState(@NotNull BuildRunnerSettings runner)
- Specified by:
selectRunnerState
in interfaceAgentRunningBuildEx
-
setCheckoutDirDirty
public void setCheckoutDirDirty(boolean checkoutDirDirty) throws RunBuildException
Depending on
checkoutDirDirty
value, marks checkout directory as either clean or dirty, both on agent and on server.If
checkoutDirDirty
istrue
, version information of checked out project sources is removed from the agent, forcing a clean checkout the next time the project is built. Note: this doesn't necessarily mean thatAgentRunningBuildEx.cleanCheckoutEnforced()
will returntrue
immediately after this method is invoked (i.e. its return value may be different from that ofAgentRunningBuildEx.isCheckoutDirDirty()
).- Specified by:
setCheckoutDirDirty
in interfaceAgentRunningBuildEx
- Parameters:
checkoutDirDirty
- iftrue
, the checkout directory is marked as dirty, otherwise it is marked as clean.- Throws:
RunBuildException
- if either server-side or agent-side status can't be changed.- See Also:
AgentRunningBuildEx.setCheckoutDirDirty(boolean)
-
clearCheckoutDirRevisions
public void clearCheckoutDirRevisions() throws RunBuildException
Description copied from interface:AgentRunningBuildEx
Deletes information about checkout directory revisions preparing directory for clean checkout.
Since, we don't keep information about revisions on server this will result in clean checkout.- Specified by:
clearCheckoutDirRevisions
in interfaceAgentRunningBuildEx
- Throws:
RunBuildException
-
isCheckoutDirDirty
public boolean isCheckoutDirDirty()
Returns the "dirty" status of the checkout directory.
- Specified by:
isCheckoutDirDirty
in interfaceAgentRunningBuildEx
- Returns:
- the "dirty" status of the checkout directory.
- See Also:
AgentRunningBuildEx.isCheckoutDirDirty()
-
-