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 voidaddSharedConfigParameter(String key, String value)Adds build wide configuration parameter.voidaddSharedEnvironmentVariable(String key, String value)Adds build wide environment variable.voidaddSharedSystemProperty(String key, String value)Adds build wide system property.booleancleanCheckoutEnforced()Indicates whether clean checkout was enforced for a build in designated directoryvoidcleanParameters()voidclearCheckoutDirRevisions()Deletes information about checkout directory revisions preparing directory for clean checkout.Stringdescribe(boolean verbose)StringgetArtifactsPaths()Returns artifacts paths specified for build.Map<String,String>getArtifactStorageSettings()BuildContextExgetBuildContext()Collection<AgentBuildFeature>getBuildFeatures()Collection<AgentBuildFeature>getBuildFeaturesOfType(String type)BuildLogTailgetBuildLogTail()StringgetBuildNumber()Returns current build number.BuildParametersMapgetBuildParameters()Returns build parameters with all references expandedFilegetCheckoutDirectory()Build state partAgentCheckoutDirRevisionInfogetCheckoutDirRevisionInfo()BuildRunnerContextExgetCurrentRunnerContext()AgentCheckoutModegetEffectiveCheckoutMode()Get checkout mode that is used for this build.booleangetFailBuildOnExitCode()Property is defined by build configuration settings to define the way build runner should process build process exit code.FullCheckoutFlaggetFullCheckoutFlag()BuildInterruptDetailsgetInterruptDetails()BuildInterruptReasongetInterruptReason()Use this method to check if build is interrupted.NodeIdHoldergetNodeIdHolder()ControlDescriptiongetParameterControlDescription(String name)Returns description object for the corresponding parameter if it is known on the agent.StringgetParameterSpec(String name)PasswordReplacergetPasswordReplacer()<T> TgetPerBuildService(Class<T> clazz)Service locator for per-build componentsMap<String,String>getRunnerParameters()Returns unmodifiable map of runner parameters with all references expandedList<BuildRunnerSettings>getRunnersToExecute()BuildParametersMapgetSharedBuildParameters()Returns build parameters.Map<String,String>getSharedConfigParameters()Returns configuration parameters of this build If you haveBuildRunnerContext, consider usingBuildRunnerContext.getConfigParameters()ValueResolvergetSharedParametersResolver()Creates value resolver for parameters resolution in strings.Map<String,String>getUnresolvedServerParameters()Return a map of all parameters which came from the TeamCity serverStringgetVcsSettingsHash()Returns hash of all vcs instance settings.FilegetWorkingDirectory()Returns build working directory: working directory where build runner startedvoidinterruptBuild(String comment, boolean reQueue)Interrupt and cancel running build.booleanisBuildFailingOnServer()Make synchronous call to the build server and check if the build is failing therebooleanisCheckoutDirDirty()Returns the "dirty" status of the checkout directory.booleanisDetachedFromAgent()Return detached status of the agent.booleanisInAlwaysExecutingStage()booleanisPreparationDone()booleanrelyOnVcsToRestoreFromErrors()voidselectRunnerState(BuildRunnerSettings runner)voidsetBuildRunnerToExecute(int buildRunnerToExecute)Sets the number of runner to execute a build step (used for purposes of Executor Mode)voidsetCheckoutDirDirty(boolean checkoutDirDirty)Depending oncheckoutDirDirtyvalue, marks checkout directory as either clean or dirty, both on agent and on server.voidsetDefaultCheckoutDirectory(AgentCheckoutMode checkoutMode)Set default checkout directory based on checkout mode that will be used in this build.voidsetDetachedFromAgent(boolean detached)Make the agent be detacheced/attached to some build.voidsetInAlwaysExecutingStage(boolean inAlwaysExecutingStage)voidsetPreparationDone()voidsetResolvedCheckoutMode(AgentCheckoutMode resolvedCheckoutMode)Set checkout method that will be used in this build.voidstopBuild(String message)Terminates execution of the build at the current build stage.StringtoString()voidupdateBuildNumber(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:
getInterruptDetailsin interfaceAgentRunningBuildEx- Returns:
- Detailed information about build interruption (if the build was interrupted)
-
setDetachedFromAgent
public void setDetachedFromAgent(boolean detached)
Description copied from interface:AgentRunningBuildExMake 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:
setDetachedFromAgentin interfaceAgentRunningBuildEx- Parameters:
detached- true if agent should be detached from its current build
-
isDetachedFromAgent
public boolean isDetachedFromAgent()
Description copied from interface:AgentRunningBuildExReturn detached status of the agent.- Specified by:
isDetachedFromAgentin interfaceAgentRunningBuildEx- Returns:
- true if the agent is detached from a build; false - otherwise
-
getInterruptReason
@Nullable public BuildInterruptReason getInterruptReason()
Description copied from interface:AgentRunningBuildUse this method to check if build is interrupted.- Specified by:
getInterruptReasonin interfaceAgentRunningBuild- Returns:
- current build interrupt reason or null if build is not interrupted
-
getFullCheckoutFlag
@NotNull public FullCheckoutFlag getFullCheckoutFlag()
- Specified by:
getFullCheckoutFlagin interfaceAgentRunningBuildEx
-
relyOnVcsToRestoreFromErrors
public boolean relyOnVcsToRestoreFromErrors()
- Specified by:
relyOnVcsToRestoreFromErrorsin 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:AgentRunningBuildExReturn a map of all parameters which came from the TeamCity server- Specified by:
getUnresolvedServerParametersin interfaceAgentRunningBuildEx- Returns:
- see above
-
getBuildParameters
@NotNull public BuildParametersMap getBuildParameters()
Description copied from interface:AgentRunningBuildReturns build parameters with all references expanded- Specified by:
getBuildParametersin interfaceAgentRunningBuild- Returns:
- see above
-
stopBuild
public void stopBuild(@NotNull String message)Description copied from interface:AgentRunningBuildTerminates 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:
stopBuildin interfaceAgentRunningBuild- Parameters:
message- build stop reason
-
cleanParameters
public void cleanParameters()
- Specified by:
cleanParametersin interfaceAgentRunningBuildEx
-
setBuildRunnerToExecute
public void setBuildRunnerToExecute(int buildRunnerToExecute)
Description copied from interface:AgentRunningBuildExSets the number of runner to execute a build step (used for purposes of Executor Mode)- Specified by:
setBuildRunnerToExecutein interfaceAgentRunningBuildEx- Parameters:
buildRunnerToExecute- number of runner to be a build step executor
-
getRunnersToExecute
@NotNull public List<BuildRunnerSettings> getRunnersToExecute()
- Specified by:
getRunnersToExecutein interfaceAgentRunningBuildEx- Returns:
-
getNodeIdHolder
@NotNull public NodeIdHolder getNodeIdHolder()
- Specified by:
getNodeIdHolderin 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:AgentRunningBuildInterrupt and cancel running build.- Specified by:
interruptBuildin 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:AgentRunningBuildReturns unmodifiable map of runner parameters with all references expanded- Specified by:
getRunnerParametersin interfaceAgentRunningBuild- Returns:
- see above
-
getFailBuildOnExitCode
public boolean getFailBuildOnExitCode()
Description copied from interface:AgentRunningBuildProperty is defined by build configuration settings to define the way build runner should process build process exit code.- Specified by:
getFailBuildOnExitCodein 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:
isInAlwaysExecutingStagein 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:
setInAlwaysExecutingStagein interfaceAgentRunningBuildEx
-
getBuildNumber
@NotNull public String getBuildNumber()
Description copied from interface:AgentRunningBuildReturns 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:
getBuildNumberin interfaceAgentRunningBuild- Returns:
- current build number
-
getWorkingDirectory
@NotNull public File getWorkingDirectory()
Description copied from interface:AgentRunningBuildReturns build working directory: working directory where build runner started- Specified by:
getWorkingDirectoryin interfaceAgentRunningBuild- Returns:
- see above
-
updateBuildNumber
public void updateBuildNumber(@NotNull String newBuildNumber)- Specified by:
updateBuildNumberin interfaceAgentRunningBuildEx
-
setPreparationDone
public void setPreparationDone()
- Specified by:
setPreparationDonein interfaceAgentRunningBuildEx
-
isPreparationDone
public boolean isPreparationDone()
- Specified by:
isPreparationDonein interfaceAgentRunningBuildEx
-
getCheckoutDirectory
@NotNull public File getCheckoutDirectory()
Build state part- Specified by:
getCheckoutDirectoryin interfaceAgentRunningBuild- Returns:
- see above
-
getEffectiveCheckoutMode
@Nullable public AgentCheckoutMode getEffectiveCheckoutMode()
Description copied from interface:AgentRunningBuildGet 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.AUTOto the server or agent-side checkout.- Specified by:
getEffectiveCheckoutModein interfaceAgentRunningBuild
-
setResolvedCheckoutMode
public void setResolvedCheckoutMode(@NotNull AgentCheckoutMode resolvedCheckoutMode)Description copied from interface:AgentRunningBuildExSet checkout method that will be used in this build.- Specified by:
setResolvedCheckoutModein interfaceAgentRunningBuildEx- See Also:
AgentRunningBuild.getEffectiveCheckoutMode()
-
setDefaultCheckoutDirectory
public void setDefaultCheckoutDirectory(@NotNull AgentCheckoutMode checkoutMode)Description copied from interface:AgentRunningBuildExSet default checkout directory based on checkout mode that will be used in this build.- Specified by:
setDefaultCheckoutDirectoryin interfaceAgentRunningBuildEx
-
getArtifactsPaths
public String getArtifactsPaths()
Description copied from interface:AgentRunningBuildReturns artifacts paths specified for build. This value is always resolved in runtime- Specified by:
getArtifactsPathsin interfaceAgentRunningBuild- Returns:
- artifacts paths
-
getArtifactStorageSettings
@NotNull public Map<String,String> getArtifactStorageSettings()
- Specified by:
getArtifactStorageSettingsin 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:AgentRunningBuildAdds build wide configuration parameter. Modifications will be available in all build runner states. If you haveBuildRunnerContext, consider usingBuildRunnerContext.addConfigParameter(String, String)*- Specified by:
addSharedConfigParameterin 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:AgentRunningBuildAdds build wide system property. Creates build parameters withConstants.SYSTEM_PREFIXprefix Modifications will be available in all build runner states. If you haveBuildRunnerContext, consider usingBuildRunnerContext.addSystemProperty(String, String)- Specified by:
addSharedSystemPropertyin 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:AgentRunningBuildAdds build wide environment variable. Creates build parameters withConstants.ENV_PREFIXprefix 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:
addSharedEnvironmentVariablein 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:AgentRunningBuildReturns build parameters. Some of values may not be fully resolved. If you haveBuildRunnerContext, consider usingBuildRunnerContext.getBuildParameters()- Specified by:
getSharedBuildParametersin interfaceAgentRunningBuild- Returns:
- build-wide build parameters
- See Also:
BuildRunnerContext.getBuildParameters()
-
getSharedConfigParameters
@NotNull public Map<String,String> getSharedConfigParameters()
Description copied from interface:AgentRunningBuildReturns configuration parameters of this build If you haveBuildRunnerContext, consider usingBuildRunnerContext.getConfigParameters()- Specified by:
getSharedConfigParametersin interfaceAgentRunningBuild- Returns:
- unmodifiable configuration parameters map
- See Also:
BuildRunnerContext.getConfigParameters()
-
getSharedParametersResolver
@NotNull public ValueResolver getSharedParametersResolver()
Description copied from interface:AgentRunningBuildCreates value resolver for parameters resolution in strings. The resolution rules are the same as for build parameters- Specified by:
getSharedParametersResolverin interfaceAgentRunningBuild- Returns:
- value resolver to perform resolution of all parameters references within string
-
getBuildFeatures
@NotNull public Collection<AgentBuildFeature> getBuildFeatures()
- Specified by:
getBuildFeaturesin interfaceAgentRunningBuild- Returns:
- collection of enabled build features for the build
-
getBuildFeaturesOfType
@NotNull public Collection<AgentBuildFeature> getBuildFeaturesOfType(@NotNull String type)
- Specified by:
getBuildFeaturesOfTypein interfaceAgentRunningBuild- Parameters:
type- type to filter features- Returns:
- collection of enabled build features for the build
-
getCheckoutDirRevisionInfo
@NotNull public AgentCheckoutDirRevisionInfo getCheckoutDirRevisionInfo()
- Specified by:
getCheckoutDirRevisionInfoin interfaceAgentRunningBuildEx- Returns:
- build checkout directory revision information
-
getBuildLogTail
@NotNull public BuildLogTail getBuildLogTail()
- Specified by:
getBuildLogTailin interfaceAgentRunningBuildEx- Returns:
- build log tail for this build
-
getParameterSpec
@Nullable public String getParameterSpec(@NotNull String name)
- Specified by:
getParameterSpecin interfaceAgentRunningBuildEx- Returns:
-
getParameterControlDescription
@Nullable public ControlDescription getParameterControlDescription(@NotNull String name)
Description copied from interface:AgentRunningBuildExReturns description object for the corresponding parameter if it is known on the agent.- Specified by:
getParameterControlDescriptionin interfaceAgentRunningBuildEx- Parameters:
name- parameter name- Returns:
- control description object which is created from the parameter spec
-
getPasswordReplacer
@NotNull public PasswordReplacer getPasswordReplacer()
- Specified by:
getPasswordReplacerin 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 InterruptedExceptionDescription copied from interface:AgentRunningBuildMake synchronous call to the build server and check if the build is failing there- Specified by:
isBuildFailingOnServerin 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:
getCurrentRunnerContextin interfaceAgentRunningBuildEx- Returns:
- build context. This context is shared between all build runners
BuildRunnerContextof the build. You may use this context to read/write build-wide parameters. Every time this method returns same object reference.BuildRunnerContextinterface may be used to update parameters for one build runner. - See Also:
BuildRunnerContext
-
getBuildContext
@NotNull public BuildContextEx getBuildContext()
- Specified by:
getBuildContextin interfaceAgentRunningBuildEx
-
getPerBuildService
@Nullable public <T> T getPerBuildService(Class<T> clazz)
Description copied from interface:AgentRunningBuildExService locator for per-build components- Specified by:
getPerBuildServicein 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:AgentRunningBuildExReturns hash of all vcs instance settings. Required to determine on agent side whether vcs settings were changed or not.- Specified by:
getVcsSettingsHashin interfaceAgentRunningBuildEx- Returns:
- hash of all vcs settings.
-
cleanCheckoutEnforced
public boolean cleanCheckoutEnforced()
Description copied from interface:AgentRunningBuildExIndicates whether clean checkout was enforced for a build in designated directory- Specified by:
cleanCheckoutEnforcedin interfaceAgentRunningBuildEx- Returns:
- true if we should do a clean checkout
-
selectRunnerState
public void selectRunnerState(@NotNull BuildRunnerSettings runner)- Specified by:
selectRunnerStatein interfaceAgentRunningBuildEx
-
setCheckoutDirDirty
public void setCheckoutDirDirty(boolean checkoutDirDirty) throws RunBuildExceptionDepending on
checkoutDirDirtyvalue, marks checkout directory as either clean or dirty, both on agent and on server.If
checkoutDirDirtyistrue, 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 returntrueimmediately after this method is invoked (i.e. its return value may be different from that ofAgentRunningBuildEx.isCheckoutDirDirty()).- Specified by:
setCheckoutDirDirtyin 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 RunBuildExceptionDescription copied from interface:AgentRunningBuildExDeletes 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:
clearCheckoutDirRevisionsin interfaceAgentRunningBuildEx- Throws:
RunBuildException
-
isCheckoutDirDirty
public boolean isCheckoutDirDirty()
Returns the "dirty" status of the checkout directory.
- Specified by:
isCheckoutDirDirtyin interfaceAgentRunningBuildEx- Returns:
- the "dirty" status of the checkout directory.
- See Also:
AgentRunningBuildEx.isCheckoutDirDirty()
-
-