Search in sources :

Example 6 with JenkinsServerConfiguration

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));
}
Also used : JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration) Test(org.junit.Test)

Example 7 with JenkinsServerConfiguration

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());
}
Also used : JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration) Test(org.junit.Test)

Example 8 with JenkinsServerConfiguration

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();
}
Also used : DBParam(net.java.ao.DBParam) JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)

Example 9 with JenkinsServerConfiguration

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);
    }
}
Also used : SQLException(java.sql.SQLException) JenkinsServer(com.offbytwo.jenkins.JenkinsServer) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration) JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration) Job(com.offbytwo.jenkins.model.Job)

Example 10 with JenkinsServerConfiguration

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);
    }
}
Also used : SQLException(java.sql.SQLException) JenkinsServer(com.offbytwo.jenkins.JenkinsServer) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration) JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration) Job(com.offbytwo.jenkins.model.Job)

Aggregations

JenkinsServerConfiguration (com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)20 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)9 SQLException (java.sql.SQLException)9 IOException (java.io.IOException)7 Test (org.junit.Test)5 JenkinsServer (com.offbytwo.jenkins.JenkinsServer)4 Job (com.offbytwo.jenkins.model.Job)4 JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)4 URISyntaxException (java.net.URISyntaxException)4 AuthorisationException (com.atlassian.stash.exception.AuthorisationException)3 Repository (com.atlassian.stash.repository.Repository)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ServletException (javax.servlet.ServletException)3 DBParam (net.java.ao.DBParam)3 SoyException (com.atlassian.soy.renderer.SoyException)2 PullRequest (com.atlassian.stash.pull.PullRequest)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2