Class JobProperty<J extends Job<?,?>>
- java.lang.Object
-
- hudson.model.JobProperty<J>
-
- Type Parameters:
J- When you restrict your job property to be only applicable to a certain subtype ofJob, you can use this type parameter to improve the type signature of this class. SeeJobPropertyDescriptor.isApplicable(Class).
- All Implemented Interfaces:
ExtensionPoint,Describable<JobProperty<?>>,ReconfigurableDescribable<JobProperty<?>>,BuildStep
- Direct Known Subclasses:
OptionalJobProperty
@ExportedBean public abstract class JobProperty<J extends Job<?,?>> extends Object implements ReconfigurableDescribable<JobProperty<?>>, BuildStep, ExtensionPoint
Extensible property ofJob.Plugins can extend this to define custom properties for
Jobs.JobPropertys show up in the user configuration screen, and they are persisted with the job object.Configuration screen should be defined in
config.jelly. Within this page, theJobPropertyinstance is available asinstancevariable (whileitrefers toJob.Starting 1.150,
JobPropertyimplementsBuildStep, meaning it gets the same hook asPublisherandBuilder. The primary intention of this mechanism is so thatJobPropertys can add actions to the new build. Theperform(AbstractBuild, Launcher, BuildListener)andprebuild(AbstractBuild, BuildListener)are invoked after those ofPublishers.Consider extending
OptionalJobPropertyinstead.- Since:
- 1.72
- Author:
- Kohsuke Kawaguchi
- See Also:
JobPropertyDescriptor
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.tasks.BuildStep
BuildStep.PublisherList
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description JobProperty()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JobPropertyDescriptorgetDescriptor()Gets the descriptor for this instance.ActiongetJobAction(J job)Deprecated.as of 1.341.Collection<? extends Action>getJobActions(J job)Actions to be displayed in the job page.Collection<?>getJobOverrides()ActiongetProjectAction(AbstractProject<?,?> project)Collection<? extends Action>getProjectActions(AbstractProject<?,?> project)BuildStepMonitorgetRequiredMonitorService()ReturnsBuildStepMonitor.NONEby default, asJobPropertys normally don't depend on its previous result.Collection<? extends SubTask>getSubTasks()ContributesSubTasks toAbstractProject.getSubTasks()booleanperform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)Runs the step over the given build and reports the progress to the listener.booleanprebuild(AbstractBuild<?,?> build, BuildListener listener)Runs before the build begins.JobProperty<?>reconfigure(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject form)When a parent/owner object of a Describable gets a config form submission and instances are recreated, this method is invoked on the existing instance (meaning the 'this' reference points to the existing instance) to create a new instance to be added to the parent/owner object.protected voidsetOwner(J owner)Hook for performing post-initialization action.
-
-
-
Method Detail
-
setOwner
protected void setOwner(J owner)
Hook for performing post-initialization action.This method is invoked in two cases. One is when the
Jobthat owns this property is loaded from disk, and the other is when a job is re-configured and all theJobPropertyinstances got re-created.
-
getDescriptor
public JobPropertyDescriptor getDescriptor()
Description copied from interface:DescribableGets the descriptor for this instance.Descriptoris a singleton for every concreteDescribableimplementation, so ifa.getClass() == b.getClass()then by defaulta.getDescriptor() == b.getDescriptor()as well. (In rare cases a single implementation class may be used for instances with distinct descriptors.)- Specified by:
getDescriptorin interfaceDescribable<J extends Job<?,?>>
-
getJobAction
@Deprecated public Action getJobAction(J job)
Deprecated.as of 1.341. OverridegetJobActions(Job)instead.
-
getJobActions
@NonNull public Collection<? extends Action> getJobActions(J job)
Actions to be displayed in the job page.Returning actions from this method allows a job property to add them to the left navigation bar in the job page.
Actioncan implement additional marker interface to integrate with the UI in different ways.- Parameters:
job- Always the same asownerbut passed in anyway for backward compatibility (I guess.) You really need not use this value at all.- Returns:
- can be empty but never null.
- Since:
- 1.341
- See Also:
ProminentProjectAction,PermalinkProjectAction
-
prebuild
public boolean prebuild(AbstractBuild<?,?> build, BuildListener listener)
Description copied from interface:BuildStepRuns before the build begins.- Specified by:
prebuildin interfaceBuildStep- Returns:
- true if the build can continue, false if there was an error
and the build needs to be aborted.
Using the return value to indicate success/failure should be considered deprecated, and implementations are encouraged to throw
AbortExceptionto indicate a failure.
-
perform
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException
Runs the step over the given build and reports the progress to the listener.A plugin can contribute the action object to
Actionable.getActions()so that a 'report' becomes a part of the persisted data ofBuild. This is how JUnit plugin attaches the test report to a build page, for example.When this build step needs to make (direct or indirect) permission checks to
ACL(for example, to locate other projects by name, build them, or access their artifacts) then it must be run under a specificAuthentication. In such a case, the implementation should check whetherJenkins.getAuthentication2()isACL.SYSTEM2, and if so, replace it for the duration of this step withJenkins.ANONYMOUS. (Either usingACL.impersonate2(org.springframework.security.core.Authentication), or by making explicit calls toACL.hasPermission2(Authentication, Permission).) This would typically happen when noQueueItemAuthenticatorwas available, configured, and active.Invoked after
Publishers have run.- Specified by:
performin interfaceBuildStep- Returns:
- true if the build can continue, false if there was an error
and the build needs to be aborted.
Using the return value to indicate success/failure should be considered deprecated, and implementations are encouraged to throw
AbortExceptionto indicate a failure. - Throws:
InterruptedException- If the build is interrupted by the user (in an attempt to abort the build.) Normally theBuildStepimplementations may simply forward the exception it got from its lower-level functions.IOException- If the implementation wants to abort the processing when anIOExceptionhappens, it can simply propagate the exception to the caller. This will cause the build to fail, with the default error message. Implementations are encouraged to catchIOExceptionon its own to provide a better error message, if it can do so, so that users have better understanding on why it failed.
-
getRequiredMonitorService
public BuildStepMonitor getRequiredMonitorService()
ReturnsBuildStepMonitor.NONEby default, asJobPropertys normally don't depend on its previous result.- Specified by:
getRequiredMonitorServicein interfaceBuildStep
-
getProjectAction
public final Action getProjectAction(AbstractProject<?,?> project)
- Specified by:
getProjectActionin interfaceBuildStep
-
getProjectActions
@NonNull public final Collection<? extends Action> getProjectActions(AbstractProject<?,?> project)
Description copied from interface:BuildStepReturns action objects if thisBuildStephas actions to contribute to aProject.Projectcalls this method for everyBuildStepthat it owns when the rendering is requested.This action can have optional
jobMain.jellyview, which will be aggregated into the main panel of the job top page. The jelly file should have an<h2>tag that shows the section title, followed by some block elements to render the details of the section.- Specified by:
getProjectActionsin interfaceBuildStep- Parameters:
project-Projectthat owns this build step, sinceBuildStepobject doesn't usually have this "parent" pointer.- Returns:
- can be empty but never null.
-
getJobOverrides
public Collection<?> getJobOverrides()
- See Also:
Job.getOverrides()
-
reconfigure
public JobProperty<?> reconfigure(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject form) throws Descriptor.FormException
Description copied from interface:ReconfigurableDescribableWhen a parent/owner object of a Describable gets a config form submission and instances are recreated, this method is invoked on the existing instance (meaning the 'this' reference points to the existing instance) to create a new instance to be added to the parent/owner object.The default implementation of this should be the following:
return form==null ? null : getDescriptor().newInstance(req, form);
- Specified by:
reconfigurein interfaceReconfigurableDescribable<J extends Job<?,?>>- Parameters:
req- The current HTTP request being processed.form- JSON fragment that corresponds to this describable object. If the newly submitted form doesn't include a fragment for this describable (meaning the user has de-selected your descriptor), then this argument is null.- Returns:
- The new instance. To not to create an instance of a describable, return null.
- Throws:
Descriptor.FormException
-
getSubTasks
public Collection<? extends SubTask> getSubTasks()
ContributesSubTasks toAbstractProject.getSubTasks()- Since:
- 1.377
-
-