/** * Remove the setupWizard filter, ensure all updates are written to disk, etc */ @RequirePOST public HttpResponse doCompleteInstall() throws IOException, ServletException { completeSetup(); return HttpResponses.okJSON(); }
/** * Called to determine if there was an incomplete installation, what the statuses of the plugins are */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doIncompleteInstallStatus() { try { Map<String,String> jobs = InstallUtil.getPersistedInstallStatus(); if(jobs == null) { jobs = Collections.emptyMap(); } return HttpResponses.okJSON(jobs); } catch (Exception e) { return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage())); } }
/** * Returns the initial plugin list in JSON format */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doPlatformPluginList() throws IOException { SetupWizard setupWizard = Jenkins.get().getSetupWizard(); if (setupWizard != null) { if (InstallState.UPGRADE.equals(Jenkins.get().getInstallState())) { JSONArray initialPluginData = getPlatformPluginUpdates(); if(initialPluginData != null) { return HttpResponses.okJSON(initialPluginData); } } else { JSONArray initialPluginData = getPlatformPluginList(); if(initialPluginData != null) { return HttpResponses.okJSON(initialPluginData); } } } return HttpResponses.okJSON(); }
return HttpResponses.okJSON(JSONObject.fromObject(response)); } catch (Exception e) { return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage()));
return HttpResponses.okJSON(ResourceBundleUtil.getBundle(baseName, locale)); } catch (Exception e) { return HttpResponses.errorJSON(e.getMessage());
@RequirePOST public HttpResponse doGenerateNewToken(@AncestorInPath User u, @QueryParameter String newTokenName) throws IOException { if(!hasCurrentUserRightToGenerateNewToken(u)){ return HttpResponses.forbidden(); } final String tokenName; if (StringUtils.isBlank(newTokenName)) { tokenName = String.format("Token created on %s", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now())); }else{ tokenName = newTokenName; } ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); if (p == null) { p = forceNewInstance(u, false); u.addProperty(p); } ApiTokenStore.TokenUuidAndPlainValue tokenUuidAndPlainValue = p.tokenStore.generateNewToken(tokenName); u.save(); return HttpResponses.okJSON(new HashMap<String, String>() {{ put("tokenUuid", tokenUuidAndPlainValue.tokenUuid); put("tokenName", tokenName); put("tokenValue", tokenUuidAndPlainValue.plainValue); }}); }
return HttpResponses.okJSON(checkJob.connectionStates); } else { return HttpResponses.errorJSON(String.format("Cannot check connection status of the update site with ID='%s'"
/** * Installs a list of plugins from a JSON POST. * @param req The request object. * @return A JSON response that includes a "correlationId" in the "data" element. * That "correlationId" can then be used in calls to * {@link UpdateCenter#doInstallStatus(org.kohsuke.stapler.StaplerRequest)}. * @throws IOException Error reading JSON payload fro request. */ @RequirePOST @Restricted(DoNotUse.class) // WebOnly public HttpResponse doInstallPlugins(StaplerRequest req) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String payload = IOUtils.toString(req.getInputStream(), req.getCharacterEncoding()); JSONObject request = JSONObject.fromObject(payload); JSONArray pluginListJSON = request.getJSONArray("plugins"); List<String> plugins = new ArrayList<>(); for (int i = 0; i < pluginListJSON.size(); i++) { plugins.add(pluginListJSON.getString(i)); } UUID correlationId = UUID.randomUUID(); try { boolean dynamicLoad = request.getBoolean("dynamicLoad"); install(plugins, dynamicLoad, correlationId); JSONObject responseData = new JSONObject(); responseData.put("correlationId", correlationId.toString()); return hudson.util.HttpResponses.okJSON(responseData); } catch (Exception e) { return hudson.util.HttpResponses.errorJSON(e.getMessage()); } }
@RequirePOST @Restricted(NoExternalUse.class) public HttpResponse doConfigureInstance(StaplerRequest req, @QueryParameter String rootUrl) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); Map<String, String> errors = new HashMap<>(); // pre-check data checkRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } // use the parameters to configure the instance useRootUrl(errors, rootUrl); if(!errors.isEmpty()){ return HttpResponses.errorJSON(Messages.SetupWizard_ConfigureInstance_ValidationErrors(), errors); } InstallUtil.proceedToNextStateFrom(InstallState.CONFIGURE_INSTANCE); CrumbIssuer crumbIssuer = Jenkins.get().getCrumbIssuer(); JSONObject data = new JSONObject(); if (crumbIssuer != null) { data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req)); } return HttpResponses.okJSON(data); }
/** * Returns whether the system needs a restart, and if it is supported * e.g. { restartRequired: true, restartSupported: false } */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doRestartStatus() throws IOException { JSONObject response = new JSONObject(); Jenkins jenkins = Jenkins.get(); response.put("restartRequired", jenkins.getUpdateCenter().isRestartRequiredForCompletion()); response.put("restartSupported", jenkins.getLifecycle().canRestart()); return HttpResponses.okJSON(response); }
return hudson.util.HttpResponses.okJSON(response);
data.accumulate("crumbRequestField", crumbIssuer.getCrumbRequestField()).accumulate("crumb", crumbIssuer.getCrumb(req)); return HttpResponses.okJSON(data); } catch (AccountCreationFailedException e) {
/** * Remove the setupWizard filter, ensure all updates are written to disk, etc */ @RequirePOST public HttpResponse doCompleteInstall() throws IOException, ServletException { completeSetup(); return HttpResponses.okJSON(); }
@Restricted(NoExternalUse.class) @RequirePOST public HttpResponse doRestartPipeline(@QueryParameter String stageName) { Map<String, String> result = new HashMap<>(); result.put("success", "false"); if (isRestartEnabled()) { try { run(stageName); result.put("success", "true"); result.put("message", "ok"); } catch (IllegalStateException ise) { result.put("message", "Failure restarting from stage: " + ise); } } else { result.put("message", "not allowed to restart"); } return HttpResponses.okJSON(result); }
/** * Called to determine if there was an incomplete installation, what the statuses of the plugins are */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doIncompleteInstallStatus() { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); try { Map<String,String> jobs = InstallUtil.getPersistedInstallStatus(); if(jobs == null) { jobs = Collections.emptyMap(); } return HttpResponses.okJSON(jobs); } catch (Exception e) { return HttpResponses.errorJSON(String.format("ERROR: %s", e.getMessage())); } }
/** * Returns the initial plugin list in JSON format */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doPlatformPluginList() throws IOException { jenkins.install.SetupWizard setupWizard = Jenkins.getInstance().getSetupWizard(); if (setupWizard != null) { if (InstallState.UPGRADE.equals(Jenkins.getInstance().getInstallState())) { JSONArray initialPluginData = getPlatformPluginUpdates(); if(initialPluginData != null) { return HttpResponses.okJSON(initialPluginData); } } else { JSONArray initialPluginData = getPlatformPluginList(); if(initialPluginData != null) { return HttpResponses.okJSON(initialPluginData); } } } return HttpResponses.okJSON(); }
/** * Returns whether the system needs a restart, and if it is supported * e.g. { restartRequired: true, restartSupported: false } */ @Restricted(DoNotUse.class) // WebOnly public HttpResponse doRestartStatus() throws IOException { JSONObject response = new JSONObject(); Jenkins jenkins = Jenkins.getInstance(); response.put("restartRequired", jenkins.getUpdateCenter().isRestartRequiredForCompletion()); response.put("restartSupported", jenkins.getLifecycle().canRestart()); return HttpResponses.okJSON(response); }
@SuppressWarnings("unused") @RequirePOST public HttpResponse doValidateJenkinsfile(StaplerRequest req) { Jenkins.getInstance().checkPermission(Jenkins.READ); JSONObject result = new JSONObject(); String groovyAsString = req.getParameter("jenkinsfile"); if (!StringUtils.isEmpty(groovyAsString)) { try { ModelASTPipelineDef pipelineDef = Converter.scriptToPipelineDef(groovyAsString); if (pipelineDef != null) { result.accumulate("result", "success"); } else { reportFailure(result, "Jenkinsfile content '" + groovyAsString + "' did not contain the 'pipeline' step"); } } catch (Exception e) { reportFailure(result, e); } } else { reportFailure(result, "No content found for 'jenkinsfile' parameter"); } return HttpResponses.okJSON(result); }
@SuppressWarnings("unused") @RequirePOST public HttpResponse doStepsToJson(StaplerRequest req) { Jenkins.getInstance().checkPermission(Jenkins.READ); JSONObject result = new JSONObject(); String groovyAsString = req.getParameter("jenkinsfile"); if (!StringUtils.isEmpty(groovyAsString)) { try { List<ModelASTStep> steps = Converter.scriptToPlainSteps(groovyAsString); JSONArray array = new JSONArray(); for (ModelASTStep step : steps) { array.add(step.toJSON()); } result.accumulate("result", "success"); result.accumulate("json", array); } catch (Exception e) { reportFailure(result, e); } } else { reportFailure(result, "No content found for 'jenkinsfile' parameter"); } return HttpResponses.okJSON(result); }
return HttpResponses.okJSON(result);