use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration in project stashbot by palantir.
the class ConfigurationTest method storesRepoInfoTest.
@Test
public void storesRepoInfoTest() throws Exception {
String url = "http://www.example.com:1234/jenkins";
String username = "jenkins_test_user";
String password = "jenkins_test_user_password";
String stashUsername = "stash_test_user";
String stashPassword = "stash_test_user_password";
Integer maxVerifyChain = 10;
int sizeOfData = ao.count(JenkinsServerConfiguration.class);
cpm.setJenkinsServerConfiguration(null, url, username, password, null, stashUsername, stashPassword, maxVerifyChain, false);
JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(null);
Assert.assertEquals("default", jsc.getName());
Assert.assertEquals(url, jsc.getUrl());
Assert.assertEquals(username, jsc.getUsername());
Assert.assertEquals(password, jsc.getPassword());
Assert.assertEquals(sizeOfData + 1, ao.count(JenkinsServerConfiguration.class));
}
use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration in project stashbot by palantir.
the class ConfigurationTest method getsDefaultjenkinsServerConfiguration.
@Test
public void getsDefaultjenkinsServerConfiguration() throws Exception {
JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(null);
Assert.assertEquals("default", jsc.getName());
Assert.assertEquals("empty", jsc.getUrl());
Assert.assertEquals("empty", jsc.getUsername());
Assert.assertEquals("empty", jsc.getPassword());
}
use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration in project stashbot by palantir.
the class ConfigurationPersistenceImpl method setJenkinsServerConfiguration.
/* (non-Javadoc)
* @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#setJenkinsServerConfiguration(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.palantir.stash.stashbot.config.JenkinsServerConfiguration.AuthenticationMode, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Boolean)
*/
@Override
public void setJenkinsServerConfiguration(String name, String url, String username, String password, AuthenticationMode authenticationMode, String stashUsername, String stashPassword, Integer maxVerifyChain, Boolean isLocked) throws SQLException {
if (name == null) {
name = DEFAULT_JENKINS_SERVER_CONFIG_KEY;
}
validateName(name);
JenkinsServerConfiguration[] configs = ao.find(JenkinsServerConfiguration.class, Query.select().where("NAME = ?", name));
if (configs.length == 0) {
log.info("Creating jenkins configuration: " + name);
ao.create(JenkinsServerConfiguration.class, new DBParam("NAME", name), new DBParam("URL", url), new DBParam("USERNAME", username), new DBParam("PASSWORD", password), new DBParam("STASH_USERNAME", stashUsername), new DBParam("STASH_PASSWORD", stashPassword), new DBParam("MAX_VERIFY_CHAIN", maxVerifyChain), new DBParam("LOCKED", isLocked));
return;
}
// already exists, so update it
configs[0].setName(name);
configs[0].setUrl(url);
configs[0].setUsername(username);
configs[0].setPassword(password);
configs[0].setAuthenticationMode(authenticationMode);
configs[0].setStashUsername(stashUsername);
configs[0].setStashPassword(stashPassword);
configs[0].setMaxVerifyChain(maxVerifyChain);
configs[0].setLocked(isLocked);
configs[0].save();
}
use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration in project stashbot by palantir.
the class JenkinsManager method createJob.
public void createJob(Repository repo, JobTemplate jobTemplate) {
try {
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
final JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
final JenkinsServer jenkinsServer = jenkinsClientManager.getJenkinsServer(jsc, rc);
final String jobName = jobTemplate.getBuildNameFor(repo);
// If we try to create a job which already exists, we still get a
// 200... so we should check first to make
// sure it doesn't already exist
Map<String, Job> jobMap = jenkinsServer.getJobs();
if (jobMap.containsKey(jobName)) {
throw new IllegalArgumentException("Job " + jobName + " already exists");
}
String xml = xmlFormatter.generateJobXml(jobTemplate, repo);
log.trace("Sending XML to jenkins to create job: " + xml);
jenkinsServer.createJob(jobName, xml);
} catch (IOException e) {
// TODO: something other than just rethrow?
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration in project stashbot by palantir.
the class JenkinsManager method updateJob.
/**
* This method IGNORES the current job XML, and regenerates it from scratch, and posts it. If any changes were made
* to the job directly via jenkins UI, this will overwrite those changes.
*
* @param repo
* @param buildType
*/
public void updateJob(Repository repo, JobTemplate jobTemplate) {
try {
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
final JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
final JenkinsServer jenkinsServer = jenkinsClientManager.getJenkinsServer(jsc, rc);
final String jobName = jobTemplate.getBuildNameFor(repo);
// If we try to create a job which already exists, we still get a
// 200... so we should check first to make
// sure it doesn't already exist
Map<String, Job> jobMap = jenkinsServer.getJobs();
String xml = xmlFormatter.generateJobXml(jobTemplate, repo);
if (jobMap.containsKey(jobName)) {
if (!rc.getPreserveJenkinsJobConfig()) {
log.trace("Sending XML to jenkins to update job: " + xml);
jenkinsServer.updateJob(jobName, xml);
} else {
log.trace("Skipping sending XML to jenkins. Repo Config is set to preserve jenkins job config.");
}
return;
}
log.trace("Sending XML to jenkins to create job: " + xml);
jenkinsServer.createJob(jobName, xml);
} catch (IOException e) {
// TODO: something other than just rethrow?
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
Aggregations