use of hudson.BulkChange in project jenkins by jenkinsci.
the class Jenkins method doConfigSubmit.
//
//
// actions
//
//
/**
* Accepts submission from the configuration page.
*/
@POST
public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
try (BulkChange bc = new BulkChange(this)) {
checkPermission(MANAGE);
JSONObject json = req.getSubmittedForm();
systemMessage = Util.nullify(req.getParameter("system_message"));
boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified()) result &= configureDescriptor(req, json, d);
save();
updateComputerList();
if (result)
FormApply.success(req.getContextPath() + '/').generateResponse(req, rsp, null);
else
// back to config
FormApply.success("configure").generateResponse(req, rsp, null);
bc.commit();
}
}
use of hudson.BulkChange in project jenkins by jenkinsci.
the class SetupWizard method init.
/**
* Initialize the setup wizard, this will process any current state initializations
*/
/*package*/
void init(boolean newInstall) throws IOException, InterruptedException {
Jenkins jenkins = Jenkins.get();
if (newInstall) {
// Create an admin user by default with a difficult password
FilePath iapf = getInitialAdminPasswordFile();
if (jenkins.getSecurityRealm() == null || jenkins.getSecurityRealm() == SecurityRealm.NO_AUTHENTICATION) {
// this seems very fragile
try (BulkChange bc = new BulkChange(jenkins)) {
HudsonPrivateSecurityRealm securityRealm = new HudsonPrivateSecurityRealm(false, false, null);
jenkins.setSecurityRealm(securityRealm);
String randomUUID = UUID.randomUUID().toString().replace("-", "").toLowerCase(Locale.ENGLISH);
// create an admin user
User initialAdmin = securityRealm.createAccount(SetupWizard.initialSetupAdminUserName, randomUUID);
if (ADMIN_INITIAL_API_TOKEN != null) {
createInitialApiToken(initialAdmin);
}
// JENKINS-33599 - write to a file in the jenkins home directory
// most native packages of Jenkins creates a machine user account 'jenkins' to run Jenkins,
// and use group 'jenkins' for admins. So we allow groups to read this file
iapf.touch(System.currentTimeMillis());
iapf.chmod(0640);
iapf.write(randomUUID + System.lineSeparator(), "UTF-8");
// Lock Jenkins down:
FullControlOnceLoggedInAuthorizationStrategy authStrategy = new FullControlOnceLoggedInAuthorizationStrategy();
authStrategy.setAllowAnonymousRead(false);
jenkins.setAuthorizationStrategy(authStrategy);
// Disable jnlp by default, but honor system properties
jenkins.setSlaveAgentPort(SystemProperties.getInteger(Jenkins.class.getName() + ".slaveAgentPort", -1));
// require a crumb issuer
jenkins.setCrumbIssuer(GlobalCrumbIssuerConfiguration.createDefaultCrumbIssuer());
// TODO could probably be removed since some of the above setters already call save
jenkins.save();
bc.commit();
}
}
if (iapf.exists()) {
String setupKey = iapf.readToString().trim();
String ls = System.lineSeparator();
LOGGER.info(ls + ls + "*************************************************************" + ls + "*************************************************************" + ls + "*************************************************************" + ls + ls + "Jenkins initial setup is required. An admin user has been created and " + "a password generated." + ls + "Please use the following password to proceed to installation:" + ls + ls + setupKey + ls + ls + "This may also be found at: " + iapf.getRemote() + ls + ls + "*************************************************************" + ls + "*************************************************************" + ls + "*************************************************************" + ls);
}
}
try {
// Make sure plugin metadata is up to date
UpdateCenter.updateDefaultSite();
} catch (RuntimeException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
}
}
use of hudson.BulkChange in project jenkins by jenkinsci.
the class Run method doConfigSubmit.
@POST
@NonNull
public HttpResponse doConfigSubmit(StaplerRequest req) throws IOException, ServletException, FormException {
checkPermission(UPDATE);
try (BulkChange bc = new BulkChange(this)) {
JSONObject json = req.getSubmittedForm();
submit(json);
bc.commit();
}
return FormApply.success(".");
}
use of hudson.BulkChange in project jenkins by jenkinsci.
the class Job method doConfigSubmit.
//
//
// actions
//
//
/**
* Accepts submission from the configuration page.
*/
@POST
public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
checkPermission(CONFIGURE);
description = req.getParameter("description");
JSONObject json = req.getSubmittedForm();
try {
try (BulkChange bc = new BulkChange(this)) {
setDisplayName(json.optString("displayNameOrNull"));
logRotator = null;
DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<>(NOOP, getAllProperties());
JSONObject jsonProperties = json.optJSONObject("properties");
if (jsonProperties != null) {
t.rebuild(req, jsonProperties, JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
} else {
t.clear();
}
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}
submit(req, rsp);
bc.commit();
}
ItemListener.fireOnUpdated(this);
final ProjectNamingStrategy namingStrategy = Jenkins.get().getProjectNamingStrategy();
if (namingStrategy.isForceExistingJobs()) {
namingStrategy.checkName(name);
}
FormApply.success(".").generateResponse(req, rsp, null);
} catch (JSONException e) {
LOGGER.log(Level.WARNING, "failed to parse " + json, e);
sendError(e, req, rsp);
}
}
use of hudson.BulkChange in project jenkins by jenkinsci.
the class Job method setBuildDiscarder.
public synchronized void setBuildDiscarder(BuildDiscarder bd) throws IOException {
try (BulkChange bc = new BulkChange(this)) {
removeProperty(BuildDiscarderProperty.class);
if (bd != null) {
addProperty(new BuildDiscarderProperty(bd));
}
bc.commit();
}
}
Aggregations