Package hudson.model

Class Job<JobT extends Job<JobT,​RunT>,​RunT extends Run<JobT,​RunT>>

    • Field Detail

      • nextBuildNumber

        protected transient volatile int nextBuildNumber
        Next build number. Kept in a separate file because this is the only information that gets updated often. This allows the rest of the configuration to be in the VCS.

        In 1.28 and earlier, this field was stored in the project configuration file, so even though this is marked as transient, don't move it around.

      • runIdMigrator

        @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
        public transient RunIdMigrator runIdMigrator
    • Method Detail

      • onCreatedFromScratch

        public void onCreatedFromScratch()
        Description copied from interface: Item
        When an item is created from scratch (instead of copied), this method will be invoked. Used as the post-construction initialization.
        Specified by:
        onCreatedFromScratch in interface Item
      • onLoad

        public void onLoad​(ItemGroup<? extends Item> parent,
                           String name)
                    throws IOException
        Description copied from class: AbstractItem
        Called right after when a Item is loaded from disk. This is an opportunity to do a post load processing.
        Specified by:
        onLoad in interface Item
        Overrides:
        onLoad in class AbstractItem
        name - Name of the directory (not a path --- just the name portion) from which the configuration was loaded. This usually becomes the name of this item.
        Throws:
        IOException
      • onCopiedFrom

        public void onCopiedFrom​(Item src)
        Description copied from class: AbstractItem
        When a Item is copied from existing one, the files are first copied on the file system, then it will be loaded, then this method will be invoked to perform any implementation-specific work.
        Specified by:
        onCopiedFrom in interface Item
        Overrides:
        onCopiedFrom in class AbstractItem
        Parameters:
        src - Item from which it's copied from. The same type as this. Never null.
      • isHoldOffBuildUntilSave

        public boolean isHoldOffBuildUntilSave()
      • isInQueue

        @Exported
        public boolean isInQueue()
      • getQueueItem

        @Exported
        public Queue.Item getQueueItem()
        If this job is in the build queue, return its item.
      • isBuilding

        public boolean isBuilding()
        Returns true if a build of this project is in progress.
      • isLogUpdated

        public boolean isLogUpdated()
        Returns true if the log file is still being updated.
      • getPronoun

        public String getPronoun()
        Description copied from class: AbstractItem
        Get the term used in the UI to represent this kind of Item. Must start with a capital letter.
        Overrides:
        getPronoun in class AbstractItem
      • isKeepDependencies

        @Exported
        public boolean isKeepDependencies()
        If true, it will keep all the build logs of dependency components. (This really only makes sense in AbstractProject but historically it was defined here.)
      • assignBuildNumber

        public int assignBuildNumber()
                              throws IOException
        Allocates a new buildCommand number.
        Throws:
        IOException
      • getNextBuildNumber

        @Exported
        public int getNextBuildNumber()
        Peeks the next build number.
      • getCharacteristicEnvVars

        public 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 via ProcessTree.killAll(Map).
      • getEnvironment

        @NonNull
        public EnvVars getEnvironment​(@CheckForNull
                                      Node node,
                                      @NonNull
                                      TaskListener listener)
                               throws IOException,
                                      InterruptedException
        Creates an environment variable override for launching processes for this project.

        This is for process launching outside the build execution (such as polling, tagging, deployment, etc.) that happens in a context of a specific job.

        Parameters:
        node - Node to eventually run a process on. The implementation must cope with this parameter being null (in which case none of the node specific properties would be reflected in the resulting override.)
        Throws:
        IOException
        InterruptedException
      • updateNextBuildNumber

        public void updateNextBuildNumber​(int next)
                                   throws IOException
        Programmatically updates the next build number.

        Much of Hudson assumes that the build number is unique and monotonic, so this method can only accept a new value that's bigger than getLastBuild() returns. Otherwise it'll be no-op.

        Throws:
        IOException
        Since:
        1.199 (before that, this method was package private.)
      • fastUpdateNextBuildNumber

        @Restricted(org.kohsuke.accmod.restrictions.Beta.class)
        public void fastUpdateNextBuildNumber​(int nextBuildNumber)
        Unconditionally sets the value of getNextBuildNumber(). Unlike updateNextBuildNumber(int) this does not save the number on disk, and does not check getLastBuild().
      • supportsLogRotator

        public boolean supportsLogRotator()
        True if this instance supports log rotation configuration.
      • removeProperty

        public <T extends JobProperty> T removeProperty​(Class<T> clazz)
                                                 throws IOException
        Removes the property of the given type.
        Returns:
        The property that was just removed.
        Throws:
        IOException
        Since:
        1.279
      • getAllProperties

        @Exported(name="property",
                  inline=true)
        public List<JobProperty<? super JobT>> getAllProperties()
        List of all JobProperty exposed primarily for the remoting API.
        Since:
        1.282
      • getProperty

        public <T extends JobProperty> T getProperty​(Class<T> clazz)
        Gets the specific property, or null if the property is not configured for this job.
      • getOverrides

        public Collection<?> getOverrides()
        Overrides from job properties.
        Specified by:
        getOverrides in interface org.kohsuke.stapler.StaplerOverridable
        See Also:
        JobProperty.getJobOverrides()
      • createHistoryWidget

        @Deprecated(forRemoval=true,
                    since="2.410")
        protected HistoryWidget createHistoryWidget()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Remove any override, history widget is now created via WidgetFactory implementation.
      • isBuildable

        @Exported
        public abstract boolean isBuildable()
        Returns true if we should display "build now" icon
      • getBuilds

        @Exported(name="allBuilds",
                  visibility=-2)
        @WithBridgeMethods(java.util.List.class)
        public RunList<RunT> getBuilds()
        Gets the read-only view of all the builds.
        Returns:
        never null. The first entry is the latest build.
      • getNewBuilds

        @Exported(name="builds")
        public RunList<RunT> getNewBuilds()
        Gets the read-only view of the recent builds.
        Since:
        1.485
      • getBuildsByTimestamp

        @WithBridgeMethods(java.util.List.class)
        @Deprecated
        public RunList<RunT> getBuildsByTimestamp​(long start,
                                                  long end)
        Deprecated.
        as of 1.372. Should just do getBuilds().byTimestamp(s,e) to avoid code bloat in Job.
        Obtains a list of builds, in the descending order, that are within the specified time range [start,end).
        Returns:
        can be empty but never null.
      • getBuildForCLI

        @CLIResolver
        public RunT getBuildForCLI​(String id)
                            throws org.kohsuke.args4j.CmdLineException
        Throws:
        org.kohsuke.args4j.CmdLineException
      • getNearestBuild

        public RunT getNearestBuild​(int n)
        Gets the youngest build #m that satisfies n&lt;=m. This is useful when you'd like to fetch a build but the exact build might be already gone (deleted, rotated, etc.)
        See Also:
        LazyBuildMixIn.getNearestBuild(int)
      • getNearestOldBuild

        public RunT getNearestOldBuild​(int n)
        Gets the latest build #m that satisfies m&lt;=n. This is useful when you'd like to fetch a build but the exact build might be already gone (deleted, rotated, etc.)
        See Also:
        LazyBuildMixIn.getNearestOldBuild(int)
      • getDynamic

        public Object getDynamic​(String token,
                                 org.kohsuke.stapler.StaplerRequest req,
                                 org.kohsuke.stapler.StaplerResponse rsp)
        Overrides:
        getDynamic in class Actionable
      • getBuildDir

        public File getBuildDir()
        Directory for storing Run records.

        Some Jobs may not have backing data store for Runs, but those Jobs that use file system for storing data should use this directory for consistency.

        See Also:
        RunMap
      • _getRuns

        protected abstract SortedMap<Integer,​? extends RunT> _getRuns()
        Gets all the runs. The resulting map must be treated immutable (by employing copy-on-write semantics.) The map is descending order, with newest builds at the top.
        See Also:
        LazyBuildMixIn._getRuns()
      • removeRun

        protected abstract void removeRun​(RunT run)
        Called from Run to remove it from this job. The files are deleted already. So all the callee needs to do is to remove a reference from this Job.
        See Also:
        LazyBuildMixIn.removeRun(RunT)
      • getLastUnsuccessfulBuild

        @Exported
        public RunT getLastUnsuccessfulBuild()
        Returns the last build that was anything but stable, if any. Otherwise null.
        See Also:
        getLastSuccessfulBuild()
      • getLastUnstableBuild

        @Exported
        public RunT getLastUnstableBuild()
        Returns the last unstable build, if any. Otherwise null.
        See Also:
        getLastSuccessfulBuild()
      • getLastStableBuild

        @Exported
        public RunT getLastStableBuild()
        Returns the last stable build, if any. Otherwise null.
        See Also:
        getLastSuccessfulBuild()
      • getLastFailedBuild

        @Exported
        public RunT getLastFailedBuild()
        Returns the last failed build, if any. Otherwise null.
      • getLastCompletedBuild

        @Exported
        public RunT getLastCompletedBuild()
        Returns the last completed build, if any. Otherwise null.
      • getLastBuildsOverThreshold

        public List<RunT> getLastBuildsOverThreshold​(int numberOfBuilds,
                                                     Result threshold)
        Returns the last numberOfBuilds builds with a build result ≥ threshold
        Returns:
        a list with the builds. May be smaller than 'numberOfBuilds' or even empty if not enough builds satisfying the threshold have been found. Never null.
      • getEstimatedDurationCandidates

        protected List<RunT> getEstimatedDurationCandidates()
        Returns candidate build for calculating the estimated duration of the current run. Returns the 3 last successful (stable or unstable) builds, if there are any. Failing to find 3 of those, it will return up to 3 last unsuccessful builds. In any case it will not go more than 6 builds into the past to avoid costly build loading.
        See Also:
        LazyBuildMixIn.getEstimatedDurationCandidates()
      • getEstimatedDuration

        public long getEstimatedDuration()
      • doRssChangelog

        public void doRssChangelog​(org.kohsuke.stapler.StaplerRequest req,
                                   org.kohsuke.stapler.StaplerResponse rsp)
                            throws IOException,
                                   javax.servlet.ServletException
        RSS feed for changes in this project.
        Throws:
        IOException
        javax.servlet.ServletException
        Since:
        2.60
      • getIconColor

        @Exported(visibility=2,
                  name="color")
        public BallColor getIconColor()
        Used as the color of the status ball for the project.
      • getBuildHealth

        public HealthReport getBuildHealth()
        Get the current health report for a job.
        Returns:
        the health report. Never returns null
      • getBuildHealthReports

        @Exported(name="healthReport")
        public List<HealthReport> getBuildHealthReports()
      • doDescription

        public void doDescription​(org.kohsuke.stapler.StaplerRequest req,
                                  org.kohsuke.stapler.StaplerResponse rsp)
                           throws IOException
        Accepts and serves the job description
        Throws:
        IOException
      • doBuildStatus

        public void doBuildStatus​(org.kohsuke.stapler.StaplerRequest req,
                                  org.kohsuke.stapler.StaplerResponse rsp)
                           throws IOException
        Returns the image that shows the current buildCommand status.
        Throws:
        IOException
      • getBuildStatusUrl

        public String getBuildStatusUrl()
      • getBuildStatusIconClassName

        public String getBuildStatusIconClassName()
      • getBuildTimeGraph

        public Graph getBuildTimeGraph()
      • checkRename

        protected void checkRename​(String newName)
                            throws Failure
        Description copied from class: AbstractItem
        Allows subclasses to block renames for domain-specific reasons. Generic validation of the new name (e.g., null checking, checking for illegal characters, and checking that the name is not in use) always happens prior to calling this method.
        Overrides:
        checkRename in class AbstractItem
        Parameters:
        newName - the new name for the item
        Throws:
        Failure - if the rename should be blocked
        See Also:
        checkRename(java.lang.String)
      • doRssAll

        public void doRssAll​(org.kohsuke.stapler.StaplerRequest req,
                             org.kohsuke.stapler.StaplerResponse rsp)
                      throws IOException,
                             javax.servlet.ServletException
        Throws:
        IOException
        javax.servlet.ServletException
      • doRssFailed

        public void doRssFailed​(org.kohsuke.stapler.StaplerRequest req,
                                org.kohsuke.stapler.StaplerResponse rsp)
                         throws IOException,
                                javax.servlet.ServletException
        Throws:
        IOException
        javax.servlet.ServletException
      • getACL

        public ACL getACL()
        Returns the ACL for this object. We need to override the identical method in AbstractItem because we won't call getACL(Job) otherwise (single dispatch)
        Specified by:
        getACL in interface AccessControlled
        Overrides:
        getACL in class AbstractItem
        Returns:
        never null.