/** * Creates a {@link TimeDuration} from the delay passed in parameter * @param delay the delay either in milliseconds without unit, or in seconds if suffixed by sec or secs. * @return the TimeDuration created from the delay expressed as a String. */ @CheckForNull public static TimeDuration fromString(@CheckForNull String delay) { if (delay == null) { return null; } long unitMultiplier = 1L; delay = delay.trim(); try { // TODO: more unit handling if (delay.endsWith("sec") || delay.endsWith("secs")) { delay = delay.substring(0, delay.lastIndexOf("sec")); delay = delay.trim(); unitMultiplier = 1000L; } return new TimeDuration(Long.parseLong(delay.trim()) * unitMultiplier); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid time duration value: "+delay); } }
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("."); } }
delay=new TimeDuration(TimeUnit.MILLISECONDS.convert(getJob().getQuietPeriod(), TimeUnit.SECONDS));
/** * 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: {@link #doBuildWithParameters(StaplerRequest, StaplerResponse, TimeDuration)} */ @Override public void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { //TODO: The below function did not have the TimeDuration param previously TimeDuration td = new TimeDuration(0); super.doBuildWithParameters(req, rsp, td); }
/** * {@inheritDoc} */ public void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { //Purge whatever's stored in the thread from a previous run //ThreadAssocStore.getInstance().clear(Thread.currentThread()); //TODO: The below function did not have the TimeDuration param previously TimeDuration td = new TimeDuration(0); super.doBuildWithParameters(req, rsp, td); }
/** * Creates a {@link TimeDuration} from the delay passed in parameter * @param delay the delay either in milliseconds without unit, or in seconds if suffixed by sec or secs. * @return the TimeDuration created from the delay expressed as a String. */ @CheckForNull public static TimeDuration fromString(@CheckForNull String delay) { if (delay == null) { return null; } long unitMultiplier = 1L; delay = delay.trim(); try { // TODO: more unit handling if (delay.endsWith("sec") || delay.endsWith("secs")) { delay = delay.substring(0, delay.lastIndexOf("sec")); delay = delay.trim(); unitMultiplier = 1000L; } return new TimeDuration(Long.parseLong(delay.trim()) * unitMultiplier); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid time duration value: "+delay); } }
@Override public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { rsp.sendRedirect(".."); rsp.setStatus(200); try { p.doBuild(req, rsp, new TimeDuration(0)); } catch (IllegalStateException e) { ; // Ignore because sendRedirect(String) gets called twice. We do not want to hit the top // level of the project but instead we want to be redirected back 1 directory. } } };
private TimeDuration getDelayFromRequest(StaplerRequest req) { return (req.hasParameter("delay")) ? TimeDuration.fromString(req.getParameter("delay")) : new TimeDuration(0); }
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; }
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("."); } }
delay = new TimeDuration(getJob().getQuietPeriod());
delay = new TimeDuration(this.getJob().getQuietPeriod());
if (delay==null) delay=new TimeDuration(getJob().getQuietPeriod());
? new TimeDuration(build.getProject().getQuietPeriod()) : new TimeDuration(0); ip.doBuild( req, rsp, delay
? new TimeDuration(build.getProject().getQuietPeriod()) : new TimeDuration(0); ip.doBuild( req, rsp, delay
delay = new TimeDuration(0);
/** * 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("."); } }