Class Run<JobT extends Job<JobT,RunT>,RunT extends Run<JobT,RunT>>
- java.lang.Object
-
- hudson.model.AbstractModelObject
-
- hudson.model.Actionable
-
- hudson.model.Run<JobT,RunT>
-
- All Implemented Interfaces:
ExtensionPoint
,DescriptorByNameOwner
,ModelObject
,PersistenceRoot
,Saveable
,SearchableModelObject
,SearchItem
,AccessControlled
,Comparable<RunT>
,ModelObjectWithContextMenu
,OnMaster
,org.kohsuke.stapler.StaplerProxy
- Direct Known Subclasses:
AbstractBuild
@ExportedBean public abstract class Run<JobT extends Job<JobT,RunT>,RunT extends Run<JobT,RunT>> extends Actionable implements ExtensionPoint, Comparable<RunT>, AccessControlled, PersistenceRoot, DescriptorByNameOwner, OnMaster, org.kohsuke.stapler.StaplerProxy
A particular execution ofJob
.Custom
Run
type is always used in conjunction with a customJob
type, so there's no separate registration mechanism for customRun
types.- Author:
- Kohsuke Kawaguchi
- See Also:
RunListener
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Run.Artifact
A build artifact.class
Run.ArtifactList
class
Run.KeepLogBuildBadge
BuildBadgeAction
that shows the build is being kept.static class
Run.RedirectUp
class
Run.RunExecution
Object that lives while the build is executed, to keep track of things that are needed only during the build.protected class
Run.Runner
Deprecated.as of 1.467 Please useRun.RunExecution
static class
Run.RunnerAbortedException
Used inRun.RunExecution.run(hudson.model.BuildListener)
to indicates that a fatal error in a build is reported toBuildListener
and the build should be simply aborted without further recording a stack trace.static class
Run.StatusSummarizer
Used to implementgetBuildStatusSummary()
.static class
Run.Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Nested classes/interfaces inherited from interface jenkins.model.ModelObjectWithContextMenu
ModelObjectWithContextMenu.ContextMenu, ModelObjectWithContextMenu.ContextMenuVisibility, ModelObjectWithContextMenu.MenuItem, ModelObjectWithContextMenu.MenuItemType
-
-
Field Summary
Fields Modifier and Type Field Description static Permission
ARTIFACTS
protected String
charset
Charset in which the log file is written.static Permission
DELETE
protected String
description
Human-readable description which is used on the main build page.protected long
duration
Number of milli-seconds it took to run this build.static FeedAdapter<Run>
FEED_ADAPTER
FeedAdapter
to produce feed from the summary of this build.static FeedAdapter<Run>
FEED_ADAPTER_LATEST
FeedAdapter
to produce feeds to show one build per project.static int
LIST_CUTOFF
Maximum number of artifacts to list before using switching to the tree view.protected RunT
nextBuild
Next build.int
number
Build number.static Comparator<Run>
ORDER_BY_DATE
Sort by date.static PermissionGroup
PERMISSIONS
protected RunT
previousBuild
Previous build.protected JobT
project
static long
QUEUE_ID_UNKNOWN
The originalQueue.Item.getId()
has not yet been mapped onto theRun
instance.protected Result
result
The build result.static boolean
SKIP_PERMISSION_CHECK
Escape hatch for StaplerProxy-based access controlprotected long
timestamp
When the build is scheduled.static int
TREE_CUTOFF
Maximum number of artifacts to show in tree view before just showing a link.static Permission
UPDATE
static com.thoughtworks.xstream.XStream
XSTREAM
static XStream2
XSTREAM2
-
Constructor Summary
Constructors Modifier Constructor Description protected
Run(JobT job)
Creates a newRun
.protected
Run(JobT job, long timestamp)
protected
Run(JobT project, File buildDir)
Loads a run from a log file.protected
Run(JobT job, Calendar timestamp)
Constructor for creating aRun
object in an arbitrary state.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected RunT
_this()
Obtains 'this' in a more type safe signature.void
addAction(Action a)
Adds a new action.boolean
canToggleLogKeep()
Checks whether keep status can be toggled.int
compareTo(RunT that)
Ordering based on build numbers.protected BuildReference<RunT>
createReference()
Called byRunMap
to obtain a reference to this run.void
delete()
Deletes this build and its entire logvoid
deleteArtifacts()
Deletes this build's artifacts.DirectoryBrowserSupport
doArtifact()
Serves the artifacts.void
doBuildNumber(org.kohsuke.stapler.StaplerResponse rsp)
Returns the build number in the body.void
doBuildStatus(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
void
doBuildTimestamp(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, String format)
Returns the build time stamp in the body.org.kohsuke.stapler.HttpResponse
doConfigSubmit(org.kohsuke.stapler.StaplerRequest req)
void
doConsoleText(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Sends out the raw console output.void
doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Deletes the build when the button is pressed.void
doProgressiveLog(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Deprecated.as of 1.352 UsegetLogText().doProgressiveText(req,rsp)
void
doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Accepts the new description.void
doToggleLogKeep(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
protected void
dropLinks()
Called byRunMap
to drop bi-directional links in preparation for deleting a build.protected void
execute(Run.RunExecution job)
static Run<?,?>
fromExternalizableId(String id)
Tries to find a run from an persisted identifier.String
getAbsoluteUrl()
Deprecated.This method shall NEVER be used during HTML page rendering, as it's too easy for misconfiguration to break this value, with network set up like Apache reverse proxy.ACL
getACL()
Obtains the ACL associated with this object.Api
getApi()
ArtifactManager
getArtifactManager()
Gets an object responsible for storing and retrieving build artifacts.List<Run.Artifact>
getArtifacts()
Gets the artifacts (relative togetArtifactsDir()
.File
getArtifactsDir()
Deprecated.Should only be used fromStandardArtifactManager
or subclasses.List<Run.Artifact>
getArtifactsUpTo(int artifactsNumber)
Gets the first N artifacts.List<BuildBadgeAction>
getBadgeActions()
Gets the subset ofActionable.getActions()
that consists ofBuildBadgeAction
s.Collection<Fingerprint>
getBuildFingerprints()
get the fingerprints associated with this buildprotected List<RunT>
getBuildsOverThreshold(int numberOfBuilds, Result threshold)
Returns the lastnumberOfBuilds
builds with a build result ≥threshold
.String
getBuildStatusIconClassName()
Run.Summary
getBuildStatusSummary()
Gets an object which represents the single line summary of the status of this build (especially in comparison with the previous build.)String
getBuildStatusUrl()
<T extends Cause>
TgetCause(Class<T> type)
Returns aCause
of a particular type.List<Cause>
getCauses()
Returns theCause
s that triggered a build.EnvVars
getCharacteristicEnvVars()
Builds up the environment variable map that's sufficient to identify a process as ours.Charset
getCharset()
Gets the charset in which the log file is written.String
getDescription()
String
getDisplayName()
long
getDuration()
Gets the millisecond it took to build.String
getDurationString()
Gets the string that says how long the build took to run.Object
getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
EnvVars
getEnvironment()
Deprecated.as of 1.305 usegetEnvironment(TaskListener)
EnvVars
getEnvironment(TaskListener listener)
Returns the map that contains environmental variables to be used for launching processes for this build.Map<String,String>
getEnvVars()
Deprecated.as of 1.292 UsegetEnvironment(TaskListener)
instead.long
getEstimatedDuration()
Returns the estimated duration for this run if it is currently running.Executor
getExecutor()
Gets theExecutor
building this job, if it's being built.String
getExternalizableId()
Produces an identifier for this run unique in the system.String
getFullDisplayName()
boolean
getHasArtifacts()
Check if theRun
contains artifacts.BallColor
getIconColor()
Gets the icon color for display.String
getId()
Unique ID of this build.String
getLog()
Deprecated.since 2007-11-11.List<String>
getLog(int maxLines)
Gets the log of the build as a list of strings (one per log line).File
getLogFile()
Deprecated.Assumes file-based storage of the log, which is not necessarily the case for Pipelines after JEP-210.InputStream
getLogInputStream()
Returns an input stream that reads from the log file.Reader
getLogReader()
AnnotatedLargeText
getLogText()
Used to URL-bindAnnotatedLargeText
.RunT
getNextBuild()
int
getNumber()
Executor
getOneOffExecutor()
Gets the one offExecutor
building this job, if it's being built.JobT
getParent()
The project this build is for.RunT
getPreviousBuild()
RunT
getPreviousBuildInProgress()
Obtains the next younger build in progress.List<RunT>
getPreviousBuildsOverThreshold(int numberOfBuilds, Result threshold)
Returns the lastnumberOfBuilds
builds with a build result ≥threshold
.RunT
getPreviousBuiltBuild()
Returns the last build that was actually built - i.e., skipping any with Result.NOT_BUILTRunT
getPreviousCompletedBuild()
Gets the most recent completed build excluding 'this' Run itself.RunT
getPreviousFailedBuild()
Returns the last failed build before this build.RunT
getPreviousNotFailedBuild()
Returns the last build that didn't fail before this build.RunT
getPreviousSuccessfulBuild()
Returns the last successful build before this build.long
getQueueId()
Get theQueue.Item.getId()
of the original queue item from where this Run instance originated.Result
getResult()
Returns the build result.File
getRootDir()
Get the root directory of thisRun
on the controller.String
getSearchUrl()
Returns the URL of this item relative to the parentSearchItem
.long
getStartTimeInMillis()
When the build has started running in an executor.Object
getTarget()
Date
getTime()
Same asgetTimestamp()
but in a different type.long
getTimeInMillis()
Same asgetTimestamp()
but in a different type, that is since the time of the epoch.Calendar
getTimestamp()
When the build is scheduled.String
getTimestampString()
Gets the string that says how long since this build has started.String
getTimestampString2()
Returns the timestamp formatted in xs:dateTime.List<Action>
getTransientActions()
Deprecated.UseActionable.getAllActions()
instead.String
getTruncatedDescription()
Deprecated.truncated description based on theTRUNCATED_DESCRIPTION_LIMIT
setting.String
getUrl()
Returns the URL of thisRun
, relative to the context root of Hudson.String
getWhyKeepLog()
IfisKeepLog()
returns true, returns a short, human-readable sentence that explains why it's being kept.boolean
hasCustomDisplayName()
boolean
hasntStartedYet()
Returns true if the build is still queued and hasn't started yet.boolean
isBuilding()
Returns true if the build is not completed yet.boolean
isInProgress()
Determine whether the run is being build right now.boolean
isKeepLog()
Returns true if this build should be kept and not deleted.boolean
isLogUpdated()
Returns true if the log file is still being updated.void
keepLog()
Marks this build to be kept.void
keepLog(boolean newValue)
protected SearchIndexBuilder
makeSearchIndex()
Default implementation that returns empty index.protected void
onEndBuilding()
Called when a job finished building normally or abnormally.protected void
onLoad()
Called after the build is loaded and the object is added to the build list.protected void
onStartBuilding()
Called when a job started building.ArtifactManager
pickArtifactManager()
Selects an object responsible for storing and retrieving build artifacts.void
reload()
Reloads the build record from disk.protected void
run(Run.Runner job)
Deprecated.as of 1.467 Useexecute(hudson.model.Run.RunExecution)
void
save()
Save the settings to a file.void
setDescription(String description)
void
setDisplayName(String value)
void
setQueueId(long queueId)
Set the queue item ID.void
setResult(Result r)
Sets thegetResult()
of this build.protected void
submit(net.sf.json.JSONObject json)
String
toString()
void
updateSymlinks(TaskListener listener)
Deprecated.After JENKINS-37862 this no longer does anything.void
writeLogTo(long offset, org.apache.commons.jelly.XMLOutput out)
Used fromconsole.jelly
to write annotated log to the given output.protected Object
writeReplace()
void
writeWholeLogTo(OutputStream out)
Writes the complete log from the start to finish to theOutputStream
.-
Methods inherited from class hudson.model.Actionable
addOrReplaceAction, doContextMenu, getAction, getAction, getActions, getActions, getAllActions, removeAction, removeActions, replaceAction, replaceActions
-
Methods inherited from class hudson.model.AbstractModelObject
getSearch, getSearchIndex, getSearchName, requirePOST, sendError, sendError, sendError, sendError, sendError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface hudson.security.AccessControlled
checkAnyPermission, checkPermission, hasAnyPermission, hasPermission, hasPermission, hasPermission2
-
Methods inherited from interface hudson.model.DescriptorByNameOwner
getDescriptorByName
-
-
-
-
Field Detail
-
QUEUE_ID_UNKNOWN
public static final long QUEUE_ID_UNKNOWN
The originalQueue.Item.getId()
has not yet been mapped onto theRun
instance.- Since:
- 1.601
- See Also:
- Constant Field Values
-
number
public transient int number
Build number.In earlier versions < 1.24, this number is not unique nor continuous, but going forward, it will, and this really replaces the build id.
-
previousBuild
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected transient volatile RunT extends Run<JobT,RunT> previousBuild
Previous build. Can be null. TODO JENKINS-22052 this is not actually implemented any more External code should usegetPreviousBuild()
-
nextBuild
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected transient volatile RunT extends Run<JobT,RunT> nextBuild
Next build. Can be null. External code should usegetNextBuild()
-
timestamp
protected long timestamp
When the build is scheduled.
-
result
protected volatile Result result
The build result. This value may change while the state is inRun.State.BUILDING
.
-
description
@CheckForNull protected volatile String description
Human-readable description which is used on the main build page. It can also be quite long, and it may use markup in a format defined by aMarkupFormatter
.getTruncatedDescription()
may be used to retrieve a size-limited description, but it implies some limitations.
-
duration
protected long duration
Number of milli-seconds it took to run this build.
-
charset
protected String charset
Charset in which the log file is written. For compatibility reason, this field may be null. For persistence, this field is string and notCharset
.- Since:
- 1.257
- See Also:
getCharset()
-
LIST_CUTOFF
public static final int LIST_CUTOFF
Maximum number of artifacts to list before using switching to the tree view.
-
TREE_CUTOFF
public static final int TREE_CUTOFF
Maximum number of artifacts to show in tree view before just showing a link.
-
XSTREAM
public static final com.thoughtworks.xstream.XStream XSTREAM
-
XSTREAM2
public static final XStream2 XSTREAM2
-
ORDER_BY_DATE
public static final Comparator<Run> ORDER_BY_DATE
Sort by date. Newer ones first.
-
FEED_ADAPTER
public static final FeedAdapter<Run> FEED_ADAPTER
FeedAdapter
to produce feed from the summary of this build.
-
FEED_ADAPTER_LATEST
public static final FeedAdapter<Run> FEED_ADAPTER_LATEST
FeedAdapter
to produce feeds to show one build per project.
-
PERMISSIONS
public static final PermissionGroup PERMISSIONS
-
DELETE
public static final Permission DELETE
-
UPDATE
public static final Permission UPDATE
-
ARTIFACTS
public static final Permission ARTIFACTS
-
SKIP_PERMISSION_CHECK
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean SKIP_PERMISSION_CHECK
Escape hatch for StaplerProxy-based access control
-
-
Constructor Detail
-
Run
protected Run(@NonNull JobT job) throws IOException
Creates a newRun
.- Parameters:
job
- Owner job- Throws:
IOException
- See Also:
LazyBuildMixIn.newBuild()
-
Run
protected Run(@NonNull JobT job, @NonNull Calendar timestamp)
Constructor for creating aRun
object in an arbitrary state.number
must be set manually.May be used in a
SubTask.createExecutable()
(instead of callingLazyBuildMixIn.newBuild()
). For example,MatrixConfiguration.newBuild
does this so that thetimestamp
as well asnumber
are shared with the parent build.
-
Run
protected Run(@NonNull JobT job, long timestamp)
- See Also:
Run(Job, Calendar)
-
Run
protected Run(@NonNull JobT project, @NonNull File buildDir) throws IOException
Loads a run from a log file.- Throws:
IOException
- See Also:
LazyBuildMixIn.loadBuild(java.io.File)
-
-
Method Detail
-
reload
public void reload() throws IOException
Reloads the build record from disk.- Throws:
IOException
- Since:
- 1.410
-
onLoad
protected void onLoad()
Called after the build is loaded and the object is added to the build list.
-
getTransientActions
@Deprecated public List<Action> getTransientActions()
Deprecated.UseActionable.getAllActions()
instead.Return all transient actions associated with this build.- Returns:
- the list can be empty but never null. read only.
-
addAction
public void addAction(@NonNull Action a)
Adds a new action. Note: calls toActionable.getAllActions()
that happen before calls to this method may not see the update. Note: this method will always modify the actions ARunAction2
is handled specially.- Overrides:
addAction
in classActionable
-
_this
@NonNull protected RunT _this()
Obtains 'this' in a more type safe signature.
-
compareTo
public int compareTo(@NonNull RunT that)
Ordering based on build numbers. If numbers are equal order based on names of parent projects.
-
getQueueId
@Exported public long getQueueId()
Get theQueue.Item.getId()
of the original queue item from where this Run instance originated.- Returns:
- The queue item ID.
- Since:
- 1.601
-
setQueueId
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void setQueueId(long queueId)
Set the queue item ID.Mapped from the
Queue.Item.getId()
.- Parameters:
queueId
- The queue item ID.
-
getResult
@Exported @CheckForNull public Result getResult()
Returns the build result.When a build is
in progress
, this method returns an intermediate result.- Returns:
- The status of the build, if it has completed or some build step has set a status; may be null if the build is ongoing.
-
setResult
public void setResult(@NonNull Result r)
Sets thegetResult()
of this build. Has no effect when the result is already set and worse than the proposed result. May only be called after the build has started and before it has moved into post-production (normally meaning bothisInProgress()
andisBuilding()
are true).- Parameters:
r
- the proposed new result- Throws:
IllegalStateException
- if the build has not yet started, is in post-production, or is complete
-
getBadgeActions
@NonNull public List<BuildBadgeAction> getBadgeActions()
Gets the subset ofActionable.getActions()
that consists ofBuildBadgeAction
s.
-
isBuilding
@Exported public boolean isBuilding()
Returns true if the build is not completed yet. This includes "not started yet" state.
-
isInProgress
@Exported public boolean isInProgress()
Determine whether the run is being build right now.- Returns:
- true if after started and before completed.
- Since:
- 1.538
-
isLogUpdated
public boolean isLogUpdated()
Returns true if the log file is still being updated.
-
getExecutor
@Exported @CheckForNull public Executor getExecutor()
Gets theExecutor
building this job, if it's being built. Otherwise null. This method looks forExecutor
who's assigned to this build, and because of that this might not be necessarily in sync with the return value ofisBuilding()
— an executor holds on toRun
some more time even after the build is finished (for example to perform post-production processing.)
-
getOneOffExecutor
@CheckForNull public Executor getOneOffExecutor()
Gets the one offExecutor
building this job, if it's being built. Otherwise null.- Since:
- 1.433
-
getCharset
@NonNull public final Charset getCharset()
Gets the charset in which the log file is written.- Returns:
- never null.
- Since:
- 1.257
-
getCauses
@NonNull public List<Cause> getCauses()
Returns theCause
s that triggered a build.If a build sits in the queue for a long time, multiple build requests made during this period are all rolled up into one build, hence this method may return a list.
- Returns:
- can be empty but never null. read-only.
- Since:
- 1.321
-
getCause
@CheckForNull public <T extends Cause> T getCause(Class<T> type)
Returns aCause
of a particular type.- Since:
- 1.362
-
isKeepLog
@Exported public final boolean isKeepLog()
Returns true if this build should be kept and not deleted. (Despite the name, this refers to the entire build, not merely the log file.) This is used as a signal to theBuildDiscarder
.
-
getWhyKeepLog
@CheckForNull public String getWhyKeepLog()
IfisKeepLog()
returns true, returns a short, human-readable sentence that explains why it's being kept.
-
getParent
@NonNull public JobT getParent()
The project this build is for.
-
getTimestamp
@Exported @NonNull public Calendar getTimestamp()
When the build is scheduled.- See Also:
getStartTimeInMillis()
-
getTime
@NonNull public final Date getTime()
Same asgetTimestamp()
but in a different type.
-
getTimeInMillis
public final long getTimeInMillis()
Same asgetTimestamp()
but in a different type, that is since the time of the epoch.
-
getStartTimeInMillis
public final long getStartTimeInMillis()
When the build has started running in an executor. For example, if a build is scheduled 1pm, and stayed in the queue for 1 hour (say, no idle agents), then this method returns 2pm, which is the time the job moved from the queue to the building state.- See Also:
getTimestamp()
-
getDescription
@Exported @CheckForNull public String getDescription()
-
getTruncatedDescription
@Deprecated @CheckForNull public String getTruncatedDescription()
Deprecated.truncated description based on theTRUNCATED_DESCRIPTION_LIMIT
setting.Returns the length-limited description. The method tries to take HTML tags within the description into account, but it is a best-effort attempt. Also, the method will likely not work properly if a non-HTMLMarkupFormatter
is used.- Returns:
- The length-limited description.
-
getTimestampString
@NonNull public String getTimestampString()
Gets the string that says how long since this build has started.- Returns:
- string like "3 minutes" "1 day" etc.
-
getTimestampString2
@NonNull public String getTimestampString2()
Returns the timestamp formatted in xs:dateTime.
-
getDurationString
@NonNull public String getDurationString()
Gets the string that says how long the build took to run.
-
getDuration
@Exported public long getDuration()
Gets the millisecond it took to build.
-
getIconColor
@NonNull public BallColor getIconColor()
Gets the icon color for display.
-
hasntStartedYet
public boolean hasntStartedYet()
Returns true if the build is still queued and hasn't started yet.
-
getFullDisplayName
@Exported public String getFullDisplayName()
-
getDisplayName
@Exported public String getDisplayName()
- Specified by:
getDisplayName
in interfaceModelObject
-
hasCustomDisplayName
public boolean hasCustomDisplayName()
-
setDisplayName
public void setDisplayName(String value) throws IOException
- Parameters:
value
- Set to null to revert back to the default "#NNN".- Throws:
IOException
-
getNumber
@Exported(visibility=2) public int getNumber()
-
createReference
@NonNull protected BuildReference<RunT> createReference()
Called byRunMap
to obtain a reference to this run.- Returns:
- Reference to the build. Never null
- Since:
- 1.556
- See Also:
LazyBuildMixIn.RunMixIn.createReference()
-
dropLinks
protected void dropLinks()
Called byRunMap
to drop bi-directional links in preparation for deleting a build.- Since:
- 1.556
- See Also:
LazyBuildMixIn.RunMixIn.dropLinks()
-
getPreviousBuild
@CheckForNull public RunT getPreviousBuild()
-
getPreviousCompletedBuild
@CheckForNull public final RunT getPreviousCompletedBuild()
Gets the most recent completed build excluding 'this' Run itself.
-
getPreviousBuildInProgress
@CheckForNull public final RunT getPreviousBuildInProgress()
Obtains the next younger build in progress. It uses a skip-pointer so that we can compute this without O(n) computation time. This method also fixes up the skip list as we go, in a way that's concurrency safe.We basically follow the existing skip list, and wherever we find a non-optimal pointer, we remember them in 'fixUp' and update them later.
-
getPreviousBuiltBuild
@CheckForNull public RunT getPreviousBuiltBuild()
Returns the last build that was actually built - i.e., skipping any with Result.NOT_BUILT
-
getPreviousNotFailedBuild
@CheckForNull public RunT getPreviousNotFailedBuild()
Returns the last build that didn't fail before this build.
-
getPreviousFailedBuild
@CheckForNull public RunT getPreviousFailedBuild()
Returns the last failed build before this build.
-
getPreviousSuccessfulBuild
@CheckForNull public RunT getPreviousSuccessfulBuild()
Returns the last successful build before this build.- Since:
- 1.383
-
getPreviousBuildsOverThreshold
@NonNull public List<RunT> getPreviousBuildsOverThreshold(int numberOfBuilds, @NonNull Result threshold)
Returns the lastnumberOfBuilds
builds with a build result ≥threshold
.- Parameters:
numberOfBuilds
- the desired number of buildsthreshold
- the build result threshold- Returns:
- a list with the builds (youngest build first). May be smaller than 'numberOfBuilds' or even empty if not enough builds satisfying the threshold have been found. Never null.
- Since:
- 1.383
-
getBuildsOverThreshold
@NonNull protected List<RunT> getBuildsOverThreshold(int numberOfBuilds, @NonNull Result threshold)
Returns the lastnumberOfBuilds
builds with a build result ≥threshold
.- Parameters:
numberOfBuilds
- the desired number of buildsthreshold
- the build result threshold- Returns:
- a list with the builds (youngest build first). May be smaller than 'numberOfBuilds' or even empty if not enough builds satisfying the threshold have been found. Never null.
- Since:
- 2.202
-
getNextBuild
@CheckForNull public RunT getNextBuild()
- See Also:
LazyBuildMixIn.RunMixIn.getNextBuild()
-
getUrl
@NonNull public String getUrl()
Returns the URL of thisRun
, relative to the context root of Hudson.- Returns:
- String like "job/foo/32/" with trailing slash but no leading slash.
-
getAbsoluteUrl
@Exported(visibility=2, name="url") @Deprecated @NonNull public final String getAbsoluteUrl()
Deprecated.This method shall NEVER be used during HTML page rendering, as it's too easy for misconfiguration to break this value, with network set up like Apache reverse proxy. This method is only intended for the remote API clients who cannot resolve relative references.Obtains the absolute URL to this build.
-
getSearchUrl
@NonNull public final String getSearchUrl()
Description copied from interface:SearchItem
Returns the URL of this item relative to the parentSearchItem
.- Specified by:
getSearchUrl
in interfaceSearchItem
- Returns:
- URL like "foo" or "foo/bar". The path can end with '/'. The path that starts with '/' will be interpreted as the absolute path (within the context path of Jenkins.)
-
getId
@Exported @NonNull public String getId()
Unique ID of this build. Usually the decimal form ofnumber
, but may be a formatted timestamp for historical builds.
-
getRootDir
@NonNull public File getRootDir()
Get the root directory of thisRun
on the controller. Files related to thisRun
should be stored below this directory.- Specified by:
getRootDir
in interfacePersistenceRoot
- Returns:
- Root directory of this
Run
on the controller. Never null
-
getArtifactManager
@NonNull public final ArtifactManager getArtifactManager()
Gets an object responsible for storing and retrieving build artifacts. IfpickArtifactManager()
has previously been called on this build, and a nondefault manager selected, that will be returned. Otherwise (including if we are loading a historical build created prior to this feature)StandardArtifactManager
is used.This method should be used when existing artifacts are to be loaded, displayed, or removed. If adding artifacts, use
pickArtifactManager()
instead.- Returns:
- an appropriate artifact manager
- Since:
- 1.532
-
pickArtifactManager
@NonNull public final ArtifactManager pickArtifactManager() throws IOException
Selects an object responsible for storing and retrieving build artifacts. The first time this is called on a running build,ArtifactManagerConfiguration
is checked to see if one will handle this build. If so, that manager is saved in the build and it will be used henceforth. If no manager claimed the build,StandardArtifactManager
is used.This method should be used when a build step expects to archive some artifacts. If only displaying existing artifacts, use
getArtifactManager()
instead.- Returns:
- an appropriate artifact manager
- Throws:
IOException
- if a custom manager was selected but the selection could not be saved- Since:
- 1.532
-
getArtifactsDir
@Deprecated public File getArtifactsDir()
Deprecated.Should only be used fromStandardArtifactManager
or subclasses.Gets the directory where the artifacts are archived.
-
getArtifacts
@Exported @NonNull public List<Run.Artifact> getArtifacts()
Gets the artifacts (relative togetArtifactsDir()
.- Returns:
- The list can be empty but never null
-
getArtifactsUpTo
@NonNull public List<Run.Artifact> getArtifactsUpTo(int artifactsNumber)
Gets the first N artifacts.- Returns:
- The list can be empty but never null
-
getHasArtifacts
public boolean getHasArtifacts()
Check if theRun
contains artifacts. The strange method name is so that we can access it from EL.- Returns:
- true if this run has any artifacts
-
getBuildFingerprints
@NonNull @Exported(name="fingerprint", inline=true, visibility=-1) public Collection<Fingerprint> getBuildFingerprints()
get the fingerprints associated with this build- Returns:
- The fingerprints
-
getLogFile
@Deprecated @NonNull public File getLogFile()
Deprecated.Assumes file-based storage of the log, which is not necessarily the case for Pipelines after JEP-210. Use other methods giving various kinds of streams such asgetLogReader()
,getLogInputStream()
, orgetLogText()
.Returns the log file.- Returns:
- The file may reference both uncompressed or compressed logs
-
getLogInputStream
@NonNull public InputStream getLogInputStream() throws IOException
Returns an input stream that reads from the log file. It will use a gzip-compressed log file (log.gz) if that exists.- Returns:
- An input stream from the log file. If the log file does not exist, the error message will be returned to the output.
- Throws:
IOException
- Since:
- 1.349
-
getLogReader
@NonNull public Reader getLogReader() throws IOException
- Throws:
IOException
-
writeLogTo
public void writeLogTo(long offset, @NonNull org.apache.commons.jelly.XMLOutput out) throws IOException
Used fromconsole.jelly
to write annotated log to the given output.- Throws:
IOException
- Since:
- 1.349
-
writeWholeLogTo
public void writeWholeLogTo(@NonNull OutputStream out) throws IOException, InterruptedException
Writes the complete log from the start to finish to theOutputStream
. If someone is still writing to the log, this method will not return until the whole log file gets written out.The method does not close the
OutputStream
.- Throws:
IOException
InterruptedException
-
getLogText
@NonNull public AnnotatedLargeText getLogText()
Used to URL-bindAnnotatedLargeText
.- Returns:
- A
Run
log with annotations
-
makeSearchIndex
@NonNull protected SearchIndexBuilder makeSearchIndex()
Description copied from class:AbstractModelObject
Default implementation that returns empty index.- Overrides:
makeSearchIndex
in classAbstractModelObject
-
getApi
@NonNull public Api getApi()
-
getACL
@NonNull public ACL getACL()
Description copied from interface:AccessControlled
Obtains the ACL associated with this object.- Specified by:
getACL
in interfaceAccessControlled
- Returns:
- never null.
-
deleteArtifacts
public void deleteArtifacts() throws IOException
Deletes this build's artifacts.- Throws:
IOException
- if we fail to delete.- Since:
- 1.350
-
delete
public void delete() throws IOException
Deletes this build and its entire log- Throws:
IOException
- if we fail to delete.
-
run
@Deprecated protected final void run(@NonNull Run.Runner job)
Deprecated.as of 1.467 Useexecute(hudson.model.Run.RunExecution)
-
execute
protected final void execute(@NonNull Run.RunExecution job)
-
updateSymlinks
@Deprecated public final void updateSymlinks(@NonNull TaskListener listener) throws InterruptedException
Deprecated.After JENKINS-37862 this no longer does anything.- Throws:
InterruptedException
-
onStartBuilding
protected void onStartBuilding()
Called when a job started building.
-
onEndBuilding
protected void onEndBuilding()
Called when a job finished building normally or abnormally.
-
save
public void save() throws IOException
Save the settings to a file.- Specified by:
save
in interfaceSaveable
- Throws:
IOException
- if the persistence failed.
-
writeReplace
protected Object writeReplace()
-
getLog
@Deprecated @NonNull public String getLog() throws IOException
Deprecated.since 2007-11-11. UsegetLog(int)
instead as it avoids loading the whole log into memory unnecessarily.Gets the log of the build as a string.- Returns:
- Returns the log or an empty string if it has not been found
- Throws:
IOException
-
getLog
@NonNull public List<String> getLog(int maxLines) throws IOException
Gets the log of the build as a list of strings (one per log line). The number of lines returned is constrained by the maxLines parameter.- Parameters:
maxLines
- The maximum number of log lines to return. If the log is bigger than this, only the most recent lines are returned.- Returns:
- A list of log lines. Will have no more than maxLines elements.
- Throws:
IOException
- If there is a problem reading the log file.
-
doBuildStatus
public void doBuildStatus(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
- Throws:
IOException
-
getBuildStatusUrl
@NonNull public String getBuildStatusUrl()
-
getBuildStatusIconClassName
public String getBuildStatusIconClassName()
-
getBuildStatusSummary
@NonNull public Run.Summary getBuildStatusSummary()
Gets an object which represents the single line summary of the status of this build (especially in comparison with the previous build.)- See Also:
Run.StatusSummarizer
-
doArtifact
@NonNull public DirectoryBrowserSupport doArtifact()
Serves the artifacts.- Throws:
org.springframework.security.access.AccessDeniedException
- Access denied
-
doBuildNumber
public void doBuildNumber(org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Returns the build number in the body.- Throws:
IOException
-
doBuildTimestamp
public void doBuildTimestamp(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp, @QueryParameter String format) throws IOException
Returns the build time stamp in the body.- Throws:
IOException
-
doConsoleText
public void doConsoleText(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Sends out the raw console output.- Throws:
IOException
-
doProgressiveLog
@Deprecated public void doProgressiveLog(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Deprecated.as of 1.352 UsegetLogText().doProgressiveText(req,rsp)
Handles incremental log output.- Throws:
IOException
-
canToggleLogKeep
public boolean canToggleLogKeep()
Checks whether keep status can be toggled. Normally it can, but if there is a complex reason (from subclasses) why this build must be kept, the toggle is meaningless.- Returns:
- true if
doToggleLogKeep(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)
andkeepLog(boolean)
andkeepLog()
are options - Since:
- 1.510
-
doToggleLogKeep
public void doToggleLogKeep(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
- Throws:
IOException
javax.servlet.ServletException
-
keepLog
@CLIMethod(name="keep-build") public final void keepLog() throws IOException
Marks this build to be kept.- Throws:
IOException
-
keepLog
public void keepLog(boolean newValue) throws IOException
- Throws:
IOException
-
doDoDelete
public void doDoDelete(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
Deletes the build when the button is pressed.- Throws:
IOException
javax.servlet.ServletException
-
setDescription
public void setDescription(String description) throws IOException
- Throws:
IOException
-
doSubmitDescription
public void doSubmitDescription(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
Accepts the new description.- Throws:
IOException
javax.servlet.ServletException
-
getEnvVars
@Deprecated public Map<String,String> getEnvVars()
Deprecated.as of 1.292 UsegetEnvironment(TaskListener)
instead.
-
getEnvironment
@Deprecated public EnvVars getEnvironment() throws IOException, InterruptedException
Deprecated.as of 1.305 usegetEnvironment(TaskListener)
- Throws:
IOException
InterruptedException
-
getEnvironment
@NonNull public EnvVars getEnvironment(@NonNull TaskListener listener) throws IOException, InterruptedException
Returns the map that contains environmental variables to be used for launching processes for this build.BuildStep
s that invoke external processes should use this. This allowsBuildWrapper
s and other project configurations (such as JDK selection) to take effect.Unlike earlier
getEnvVars()
, this map contains the whole environment, not just the overrides, so one can introspect values to change its behavior.- Returns:
- the map with the environmental variables.
- Throws:
IOException
InterruptedException
- Since:
- 1.305
-
getCharacteristicEnvVars
@NonNull public final EnvVars getCharacteristicEnvVars()
Builds up the environment variable map that's sufficient to identify a process as ours. This is used to kill run-away processes viaProcessTree.killAll(Map)
.
-
getExternalizableId
@NonNull public String getExternalizableId()
Produces an identifier for this run unique in the system.- Returns:
- the
AbstractItem.getFullName()
, then#
, thengetNumber()
- See Also:
fromExternalizableId(java.lang.String)
-
fromExternalizableId
@CheckForNull public static Run<?,?> fromExternalizableId(String id) throws IllegalArgumentException, org.springframework.security.access.AccessDeniedException
Tries to find a run from an persisted identifier.- Parameters:
id
- as produced bygetExternalizableId()
- Returns:
- the same run, or null if the job or run was not found
- Throws:
IllegalArgumentException
- if the ID is malformedorg.springframework.security.access.AccessDeniedException
- as perItemGroup.getItem(java.lang.String)
-
getEstimatedDuration
@Exported public long getEstimatedDuration()
Returns the estimated duration for this run if it is currently running. Default toJob.getEstimatedDuration()
, may be overridden in subclasses if duration may depend on run specific parameters (like incremental Maven builds).- Returns:
- the estimated duration in milliseconds
- Since:
- 1.383
-
doConfigSubmit
@POST @NonNull public org.kohsuke.stapler.HttpResponse doConfigSubmit(org.kohsuke.stapler.StaplerRequest req) throws IOException, javax.servlet.ServletException, Descriptor.FormException
- Throws:
IOException
javax.servlet.ServletException
Descriptor.FormException
-
submit
protected void submit(net.sf.json.JSONObject json) throws IOException
- Throws:
IOException
-
getDynamic
public Object getDynamic(String token, org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
- Overrides:
getDynamic
in classActionable
-
getTarget
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public Object getTarget()
- Specified by:
getTarget
in interfaceorg.kohsuke.stapler.StaplerProxy
-
-