/** * Computes the build cause, using RemoteCause or UserCause as appropriate. */ @Restricted(NoExternalUse.class) public static final CauseAction getBuildCause(ParameterizedJob job, StaplerRequest req) { Cause cause; @SuppressWarnings("deprecation") hudson.model.BuildAuthorizationToken authToken = job.getAuthToken(); if (authToken != null && authToken.getToken() != null && req.getParameter("token") != null) { // Optional additional cause text when starting via token String causeText = req.getParameter("cause"); cause = new Cause.RemoteCause(req.getRemoteAddr(), causeText); } else { cause = new Cause.UserIdCause(); } return new CauseAction(cause); }
@Deprecated public static void checkPermission(AbstractProject<?,?> project, BuildAuthorizationToken token, StaplerRequest req, StaplerResponse rsp) throws IOException { Job<?,?> j = project; checkPermission(j, token, req, rsp); }
public Object fromString(String str) { return new BuildAuthorizationToken(str); }
authToken = BuildAuthorizationToken.create(req);
@SuppressWarnings("deprecation") @Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { super.submit(req, rsp); JSONObject json = req.getSubmittedForm(); definition = req.bindJSON(FlowDefinition.class, json.getJSONObject("definition")); authToken = hudson.model.BuildAuthorizationToken.create(req); if (req.getParameter("hasCustomQuietPeriod") != null) { quietPeriod = Integer.parseInt(req.getParameter("quiet_period")); } else { quietPeriod = null; } makeDisabled(json.optBoolean("disable")); }
@Override // in case schedulePolling was overridden public void doPolling( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { BuildAuthorizationToken.checkPermission((Job) this, authToken, req, rsp); schedulePolling(); rsp.sendRedirect("."); }
@SuppressWarnings("deprecation") private static boolean jobHasAuthToken(final hudson.model.BuildAuthorizationToken authToken) { return authToken != null && !isNullOrEmpty(authToken.getToken()); }
public static BuildAuthorizationToken create(StaplerRequest req) { if (req.getParameter("pseudoRemoteTrigger") != null) { String token = Util.fixEmpty(req.getParameter("authToken")); if(token!=null) return new BuildAuthorizationToken(token); } return null; }
setConcurrentBuild(json.has("concurrentBuild")); authToken = BuildAuthorizationToken.create(req);
/** * Schedules a new SCM polling command. */ @SuppressWarnings("deprecation") default void doPolling(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (!(this instanceof SCMTriggerItem)) { rsp.sendError(404); return; } hudson.model.BuildAuthorizationToken.checkPermission((Job) this, getAuthToken(), req, rsp); ((SCMTriggerItem) this).schedulePolling(); rsp.sendRedirect("."); }
/** This is the token configured in the job. A feature found in Jenkins core. */ @SuppressWarnings("deprecation") private static boolean authenticationTokenMatches( final hudson.model.BuildAuthorizationToken authToken, final String givenToken) { final boolean jobHasAuthToken = jobHasAuthToken(authToken); final boolean authTokenWasGiven = !isNullOrEmpty(givenToken); if (jobHasAuthToken && authTokenWasGiven) { return authToken.getToken().equals(givenToken); } if (!jobHasAuthToken && !authTokenWasGiven) { return true; } return false; }
public Object fromString(String str) { return new BuildAuthorizationToken(str); }
@Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req,rsp); makeDisabled(null != req.getParameter("disable")); setJDK(req.getParameter("jdk")); setQuietPeriod(null != req.getParameter(HAS_QUIET_PERIOD_PROPERTY_NAME) ? req.getParameter("quiet_period") : null); setScmCheckoutRetryCount(null != req.getParameter(HAS_SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME) ? req.getParameter("scmCheckoutRetryCount") : null); setBlockBuildWhenDownstreamBuilding(null != req.getParameter("blockBuildWhenDownstreamBuilding")); setBlockBuildWhenUpstreamBuilding(null != req.getParameter("blockBuildWhenUpstreamBuilding")); if (req.getParameter(APPOINTED_NODE_PROPERTY_NAME) != null) { // New logic for handling whether this choice came from the dropdown or textfield. if (BASIC_KEY.equals(req.getParameter(AFFINITY_CHO0SER_KEY))) { setAppointedNode( new AppointedNode(Util.fixEmptyAndTrim(req.getParameter(SLAVE_KEY)), false)); } else { setAppointedNode( new AppointedNode(Util.fixEmptyAndTrim(req.getParameter(ASSIGNED_LABEL_KEY)), true)); } } else { setAppointedNode(null); } setCleanWorkspaceRequired(null != req.getParameter("cleanWorkspaceRequired")); setConcurrentBuild(req.getSubmittedForm().has("concurrentBuild")); authToken = BuildAuthorizationToken.create(req); setScm(SCMS.parseSCM(req,this)); buildTriggers(req, req.getSubmittedForm(), Trigger.for_(this)); }
/** * Standard implementation of {@link ParameterizedJob#doBuildWithParameters}. */ @SuppressWarnings("deprecation") public final void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { hudson.model.BuildAuthorizationToken.checkPermission(asJob(), asJob().getAuthToken(), req, rsp); ParametersDefinitionProperty pp = asJob().getProperty(ParametersDefinitionProperty.class); if (!asJob().isBuildable()) { throw HttpResponses.error(SC_CONFLICT, new IOException(asJob().getFullName() + " is not buildable!")); } if (pp != null) { pp.buildWithParameters(req, rsp, delay); } else { throw new IllegalStateException("This build is not parameterized!"); } }
/** * Computes the build cause, using RemoteCause or UserCause as appropriate. */ /*package*/ CauseAction getBuildCause(StaplerRequest req) { Cause cause; if (authToken != null && authToken.getToken() != null && req.getParameter("token") != null) { // Optional additional cause text when starting via token String causeText = req.getParameter("cause"); cause = new RemoteCause(req.getRemoteAddr(), causeText); } else { cause = new UserCause(); } return new CauseAction(cause); }
public Object fromString(String str) { return new BuildAuthorizationToken(str); }
@Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req, rsp); makeDisabled(null != req.getParameter("disable")); setJDK(req.getParameter("jdk")); setQuietPeriod(null != req.getParameter(HAS_QUIET_PERIOD_PROPERTY_NAME) ? req.getParameter("quiet_period") : null); setScmCheckoutRetryCount(null != req.getParameter(HAS_SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME) ? req.getParameter("scmCheckoutRetryCount") : null); setBlockBuildWhenDownstreamBuilding(null != req.getParameter("blockBuildWhenDownstreamBuilding")); setBlockBuildWhenUpstreamBuilding(null != req.getParameter("blockBuildWhenUpstreamBuilding")); if (req.getParameter(APPOINTED_NODE_PROPERTY_NAME) != null) { // New logic for handling whether this choice came from the dropdown or textfield. if (BASIC_KEY.equals(req.getParameter(AFFINITY_CHO0SER_KEY))) { setAppointedNode( new AppointedNode(Util.fixEmptyAndTrim(req.getParameter(SLAVE_KEY)), false)); } else { setAppointedNode( new AppointedNode(Util.fixEmptyAndTrim(req.getParameter(ASSIGNED_LABEL_KEY)), true)); } } else { setAppointedNode(null); } setCleanWorkspaceRequired(null != req.getParameter("cleanWorkspaceRequired")); setConcurrentBuild(req.getSubmittedForm().has("concurrentBuild")); authToken = BuildAuthorizationToken.create(req); setScm(SCMS.parseSCM(req, this)); buildTriggers(req, req.getSubmittedForm(), Trigger.for_(this)); }
/** * 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("."); } }
/** * Computes the build cause, using RemoteCause or UserCause as appropriate. */ /*package*/ CauseAction getBuildCause(StaplerRequest req) { Cause cause; if (authToken != null && authToken.getToken() != null && req.getParameter("token") != null) { // Optional additional cause text when starting via token String causeText = req.getParameter("cause"); cause = new RemoteCause(req.getRemoteAddr(), causeText); } else { cause = new UserCause(); } return new CauseAction(cause); }
public Object fromString(String str) { return new BuildAuthorizationToken(str); }