/** * Convenience method to schedule a build. * Useful for {@link Trigger} implementations, for example. * If you need to wait for the build to start (or finish), use {@link Queue.Item#getFuture}. * @param job a job which might be schedulable * @param quietPeriod seconds to wait before starting; use {@code -1} to use the job’s default settings * @param actions various actions to associate with the scheduling, such as {@link ParametersAction} or {@link CauseAction} * @return a newly created, or reused, queue item if the job could be scheduled; null if it was refused for some reason (e.g., some {@link Queue.QueueDecisionHandler} rejected it), or if {@code job} is not a {@link ParameterizedJob} or it is not {@link Job#isBuildable}) * @since 1.621 */ public static @CheckForNull Queue.Item scheduleBuild2(final Job<?,?> job, int quietPeriod, Action... actions) { if (!(job instanceof ParameterizedJob)) { return null; } return new ParameterizedJobMixIn() { @Override protected Job asJob() { return job; } }.scheduleBuild2(quietPeriod == -1 ? ((ParameterizedJob) job).getQuietPeriod() : quietPeriod, Arrays.asList(actions)); }
public void buildWithParameters(StaplerRequest req, StaplerResponse rsp, @CheckForNull TimeDuration delay) throws IOException, ServletException { List<ParameterValue> values = new ArrayList<ParameterValue>(); for (ParameterDefinition d: parameterDefinitions) { ParameterValue value = d.createValue(req); if (value != null) { values.add(value); } } if (delay==null) delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(getJob().getQuietPeriod(), TimeUnit.SECONDS)); Queue.Item item = Jenkins.getInstance().getQueue().schedule2( getJob(), delay.getTimeInSeconds(), new ParametersAction(values), ParameterizedJobMixIn.getBuildCause(getJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
continue; boolean scheduled = pj.scheduleBuild(pj.getQuietPeriod(), new UpstreamCause((Run) build)); if (Jenkins.getInstance().getItemByFullName(downstream.getFullName()) == downstream) { String name = ModelHyperlinkNote.encodeTo(downstream);
Object mixinJob = FieldUtils.readField(parameterizedJobMixIn, "val$job", true); ParameterizedJobMixIn.ParameterizedJob parameterizedJob = (ParameterizedJobMixIn.ParameterizedJob) mixinJob; quietPeriod = parameterizedJob.getQuietPeriod(); } catch (IllegalAccessException e) { LOGGER.error("Couldn't extract quiet period, falling back to {}", quietPeriod, e);
Object mixinJob = FieldUtils.readField(parameterizedJobMixIn, "val$job", true); ParameterizedJobMixIn.ParameterizedJob parameterizedJob = (ParameterizedJobMixIn.ParameterizedJob) mixinJob; quietPeriod = parameterizedJob.getQuietPeriod(); } catch (IllegalAccessException e) { LOGGER.error("Couldn't extract quiet period, falling back to {}", quietPeriod, e);
if (delay==null) delay=new TimeDuration(getJob().getQuietPeriod());
private JSONObject innerDispatch(final StaplerRequest req, final StaplerResponse rsp, final TimeDuration delay) throws IOException, ServletException { commandName = null; jobName = null; final String pathInfo = req.getPathInfo(); if (!decodeCommandAndJobNames(pathInfo)) { if (commandName == null) { throw new IllegalArgumentException("Command not provided"); } if (jobName == null) { throw new IllegalArgumentException("Job name not provided after command"); } } if (!COMMAND_FACTORIES_BY_NAME.containsKey(commandName)) { throw new IllegalArgumentException("Command not implemented"); } final Job job = getJob(jobName, req); final ParameterizedJobMixIn.ParameterizedJob jobMixin = (ParameterizedJobMixIn.ParameterizedJob) job; checkPermission(job, jobMixin, req, rsp); final TimeDuration actualDelay = delay == null ? new TimeDuration(jobMixin.getQuietPeriod()) : delay; final AbstractCommand.Factory factory = COMMAND_FACTORIES_BY_NAME.get(commandName); final AbstractCommand command = factory.create(); final JSONObject response; final JSONObject formData = req.getSubmittedForm(); final ObjectMapper mapper = EndpointHelper.MAPPER; final TeamBuildPayload teamBuildPayload = mapper.convertValue(formData, TeamBuildPayload.class); final BuildableItem buildable = (BuildableItem) job; response = command.perform(job, buildable, req, formData, mapper, teamBuildPayload, actualDelay); return response; }
/** * Standard implementation of {@link ParameterizedJob#doBuild}. */ @SuppressWarnings("deprecation") public final void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { if (delay == null) { delay = new TimeDuration(asJob().getQuietPeriod()); } if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable")); } // if a build is parameterized, let that take over ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (pp != null && !req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(pp, "index.jelly").forward(req, rsp); return; } hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); if (pp != null) { pp._doBuild(req, rsp, delay); return; } Queue.Item item = Jenkins.getInstance().getQueue().schedule2(asJob(), delay.getTimeInSeconds(), getBuildCause(asJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
boolean schedule(Cause cause) { if (!asJob().isBuildable()) { return false; } List<Action> queueActions = new LinkedList<Action>(); queueActions.add(new ParametersAction(getParameterValues())); queueActions.add(new CauseAction(cause)); int quiet = Math.max(MIN_QUIET, asJob().getQuietPeriod()); final Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { logger.log(Level.WARNING, "Tried to schedule a build while Jenkins was gone."); return false; } final Queue queue = jenkins.getQueue(); if (queue == null) { throw new IllegalStateException("The queue is not initialized?!"); } Queue.Item i = queue.schedule2(asJob(), quiet, queueActions).getItem(); return i != null && i.getFuture() != null; }
/** * Convenience method to schedule a build. * Useful for {@link Trigger} implementations, for example. * If you need to wait for the build to start (or finish), use {@link Queue.Item#getFuture}. * @param job a job which might be schedulable * @param quietPeriod seconds to wait before starting; use {@code -1} to use the job’s default settings * @param actions various actions to associate with the scheduling, such as {@link ParametersAction} or {@link CauseAction} * @return a newly created, or reused, queue item if the job could be scheduled; null if it was refused for some reason (e.g., some {@link Queue.QueueDecisionHandler} rejected it), or if {@code job} is not a {@link ParameterizedJob} or it is not {@link Job#isBuildable}) * @since 1.621 */ public static @CheckForNull Queue.Item scheduleBuild2(final Job<?,?> job, int quietPeriod, Action... actions) { if (!(job instanceof ParameterizedJob)) { return null; } return new ParameterizedJobMixIn() { @Override protected Job asJob() { return job; } }.scheduleBuild2(quietPeriod == -1 ? ((ParameterizedJob) job).getQuietPeriod() : quietPeriod, Arrays.asList(actions)); }
public void buildWithParameters(StaplerRequest req, StaplerResponse rsp, @CheckForNull TimeDuration delay) throws IOException, ServletException { List<ParameterValue> values = new ArrayList<ParameterValue>(); for (ParameterDefinition d: parameterDefinitions) { ParameterValue value = d.createValue(req); if (value != null) { values.add(value); } } if (delay==null) delay=new TimeDuration(getJob().getQuietPeriod()); Queue.Item item = Jenkins.getInstance().getQueue().schedule2( getJob(), delay.getTimeInSeconds(), new ParametersAction(values), ParameterizedJobMixIn.getBuildCause(getJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
@CheckForNull protected Future schedule(@Nonnull AbstractBuild<?, ?> build, @Nonnull Job project, @Nonnull List<Action> list, @Nonnull TaskListener listener) throws InterruptedException, IOException { if (project instanceof ParameterizedJobMixIn.ParameterizedJob) { return schedule(build, project, ((ParameterizedJobMixIn.ParameterizedJob) project).getQuietPeriod(), list, listener); } else { return schedule(build, project, 0, list, listener); } }
/** @see BuildableItem#scheduleBuild() */ @SuppressWarnings("deprecation") public final boolean scheduleBuild() { return scheduleBuild(asJob().getQuietPeriod(), new Cause.LegacyCodeCause()); }
/** @see BuildableItem#scheduleBuild(Cause) */ public final boolean scheduleBuild(Cause c) { return scheduleBuild(asJob().getQuietPeriod(), c); }
delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(getJob().getQuietPeriod(), TimeUnit.SECONDS));
private void scheduleBuild(Job<?, ?> job, Action[] actions) { int projectBuildDelay = 0; if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { ParameterizedJobMixIn.ParameterizedJob abstractProject = (ParameterizedJobMixIn.ParameterizedJob) job; if (abstractProject.getQuietPeriod() > projectBuildDelay) { projectBuildDelay = abstractProject.getQuietPeriod(); } } retrieveScheduleJob(job).scheduleBuild2(projectBuildDelay, actions); }
protected void scheduleBuild(Job<?, ?> job, Action[] actions) { int projectBuildDelay = 0; if (job instanceof ParameterizedJobMixIn.ParameterizedJob) { ParameterizedJobMixIn.ParameterizedJob abstractProject = (ParameterizedJobMixIn.ParameterizedJob) job; if (abstractProject.getQuietPeriod() > projectBuildDelay) { projectBuildDelay = abstractProject.getQuietPeriod(); } } retrieveScheduleJob(job).scheduleBuild2(projectBuildDelay, actions); }
/** * Standard implementation of {@link ParameterizedJob#doBuild}. */ @SuppressWarnings("deprecation") public final void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { if (delay == null) { delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(asJob().getQuietPeriod(), TimeUnit.SECONDS)); } if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable")); } // if a build is parameterized, let that take over ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (pp != null && !req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(pp, "index.jelly").forward(req, rsp); return; } hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); if (pp != null) { pp._doBuild(req, rsp, delay); return; } Queue.Item item = Jenkins.getInstance().getQueue().schedule2(asJob(), delay.getTimeInSeconds(), getBuildCause(asJob(), req)).getItem(); if (item != null) { rsp.sendRedirect(SC_CREATED, req.getContextPath() + '/' + item.getUrl()); } else { rsp.sendRedirect("."); } }
/** @see BuildableItem#scheduleBuild(Cause) */ public final boolean scheduleBuild(Cause c) { return scheduleBuild(asJob().getQuietPeriod(), c); }
/** @see BuildableItem#scheduleBuild() */ @SuppressWarnings("deprecation") public final boolean scheduleBuild() { return scheduleBuild(asJob().getQuietPeriod(), new Cause.LegacyCodeCause()); }