Search in sources :

Example 1 with DockerCloud

use of com.nirima.jenkins.plugins.docker.DockerCloud in project configuration-as-code-plugin by jenkinsci.

the class DockerCloudTest method update_docker_cloud.

@Test
@ConfiguredWithReadme("docker/README.md")
public void update_docker_cloud() throws Exception {
    DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    DockerTemplate template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
    ConfigurationAsCode.get().configure(getClass().getResource("DockerCloudTest2.yml").toExternalForm());
    docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
    template = docker.getTemplate(Label.get("generic"));
    checkTemplate(template, "generic", "jenkins", "/home/jenkins/agent2", "5", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
}
Also used : DockerTemplate(com.nirima.jenkins.plugins.docker.DockerTemplate) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Example 2 with DockerCloud

use of com.nirima.jenkins.plugins.docker.DockerCloud in project configuration-as-code-plugin by jenkinsci.

the class JenkinsDemoTest method configure_demo_yaml.

@Test
@ConfiguredWithCode("jenkins/jenkins.yaml")
public void configure_demo_yaml() {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
    assertEquals(5, jenkins.getNumExecutors());
    assertEquals(2, jenkins.getScmCheckoutRetryCount());
    assertEquals(Mode.NORMAL, jenkins.getMode());
    assertEquals("https://ci.example.com/", jenkins.getRootUrl());
    final FullControlOnceLoggedInAuthorizationStrategy strategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
    assertFalse(strategy.isAllowAnonymousRead());
    final DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
    assertEquals(1, gitTool.getInstallations().length);
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("awesome-lib", library.getName());
    final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
    assertEquals("4441", descriptor.getSmtpPort());
    assertEquals("do-not-reply@acme.org", descriptor.getReplyToAddress());
    assertEquals("smtp.acme.org", descriptor.getSmtpHost());
    final ArtifactoryBuilder.DescriptorImpl artifactory = (ArtifactoryBuilder.DescriptorImpl) jenkins.getDescriptor(ArtifactoryBuilder.class);
    assertTrue(artifactory.getUseCredentialsPlugin());
    final List<JFrogPlatformInstance> jfrogInstances = artifactory.getJfrogInstances();
    assertThat(jfrogInstances, hasSize(1));
    assertThat(jfrogInstances.get(0).getId(), is(equalTo("artifactory")));
    assertThat(jfrogInstances.get(0).getUrl(), is(equalTo("http://acme.com/artifactory")));
    assertThat(jfrogInstances.get(0).getResolverCredentialsConfig().getUsername(), is(equalTo("artifactory_user")));
    assertThat(jfrogInstances.get(0).getResolverCredentialsConfig().getPassword().getPlainText(), is(equalTo("password123")));
}
Also used : FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) Mailer(hudson.tasks.Mailer) ArtifactoryBuilder(org.jfrog.hudson.ArtifactoryBuilder) JFrogPlatformInstance(org.jfrog.hudson.JFrogPlatformInstance) Jenkins(jenkins.model.Jenkins) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) GitTool(hudson.plugins.git.GitTool) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 3 with DockerCloud

use of com.nirima.jenkins.plugins.docker.DockerCloud in project configuration-as-code-plugin by jenkinsci.

the class DockerCloudTest method configure_docker_cloud.

@Test
@ConfiguredWithCode("DockerCloudTest.yml")
public void configure_docker_cloud() throws Exception {
    final DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    final DockerTemplate template = docker.getTemplate("jenkins/slave");
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10");
}
Also used : DockerTemplate(com.nirima.jenkins.plugins.docker.DockerTemplate) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 4 with DockerCloud

use of com.nirima.jenkins.plugins.docker.DockerCloud in project configuration-as-code-plugin by jenkinsci.

the class DockerCloudTest method update_docker_cloud.

@Test
@ConfiguredWithCode("DockerCloudTest/update_docker_cloud/DockerCloudTest1.yml")
public void update_docker_cloud() throws Exception {
    DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    DockerTemplate template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10");
    TestConfiguration.withCode("DockerCloudTest/update_docker_cloud/DockerCloudTest2.yml").configure(getClass());
    docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    template = docker.getTemplate(Label.get("docker-agent"));
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10");
    template = docker.getTemplate(Label.get("generic"));
    checkTemplate(template, "generic", "jenkins", "/home/jenkins/agent2", "5");
}
Also used : DockerTemplate(com.nirima.jenkins.plugins.docker.DockerTemplate) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 5 with DockerCloud

use of com.nirima.jenkins.plugins.docker.DockerCloud in project configuration-as-code-plugin by jenkinsci.

the class DockerCloudTest method configure_docker_cloud.

@Test
@ConfiguredWithReadme("docker/README.md")
public void configure_docker_cloud() {
    final DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());
    final DockerTemplate template = docker.getTemplate("jenkins/agent");
    checkTemplate(template, "docker-agent", "jenkins", "/home/jenkins/agent", "10", new String[] { "hello:/hello", "world:/world" }, "hello=world\nfoo=bar");
    assertTrue(template.getRetentionStrategy() instanceof DockerOnceRetentionStrategy);
    assertEquals(1, ((DockerOnceRetentionStrategy) template.getRetentionStrategy()).getIdleMinutes());
}
Also used : DockerTemplate(com.nirima.jenkins.plugins.docker.DockerTemplate) DockerCloud(com.nirima.jenkins.plugins.docker.DockerCloud) DockerOnceRetentionStrategy(com.nirima.jenkins.plugins.docker.strategy.DockerOnceRetentionStrategy) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

DockerCloud (com.nirima.jenkins.plugins.docker.DockerCloud)5 Test (org.junit.Test)5 DockerTemplate (com.nirima.jenkins.plugins.docker.DockerTemplate)4 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)2 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)2 DockerOnceRetentionStrategy (com.nirima.jenkins.plugins.docker.strategy.DockerOnceRetentionStrategy)1 GitTool (hudson.plugins.git.GitTool)1 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)1 Mailer (hudson.tasks.Mailer)1 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)1 Jenkins (jenkins.model.Jenkins)1 LibraryConfiguration (org.jenkinsci.plugins.workflow.libs.LibraryConfiguration)1 ArtifactoryBuilder (org.jfrog.hudson.ArtifactoryBuilder)1 JFrogPlatformInstance (org.jfrog.hudson.JFrogPlatformInstance)1