Search in sources :

Example 1 with GitTool

use of hudson.plugins.git.GitTool 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 2 with GitTool

use of hudson.plugins.git.GitTool in project configuration-as-code-plugin by jenkinsci.

the class TopReadmeTest method configure_demo_first_code_block.

@Test
@ConfiguredWithReadme("README.md#0")
public void configure_demo_first_code_block() {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
    final LDAPSecurityRealm securityRealm = (LDAPSecurityRealm) jenkins.getSecurityRealm();
    assertEquals(1, securityRealm.getConfigurations().size());
    assertEquals(50000, jenkins.getSlaveAgentPort());
    assertEquals(1, jenkins.getNodes().size());
    assertEquals("static-agent", jenkins.getNode("static-agent").getNodeName());
    final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
    assertEquals(1, gitTool.getInstallations().length);
    List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(sshPrivateKeys, hasSize(1));
    final BasicSSHUserPrivateKey ssh_with_passphrase = sshPrivateKeys.get(0);
    assertThat(ssh_with_passphrase.getPassphrase().getPlainText(), equalTo("ABCD"));
    final DirectEntryPrivateKeySource source = (DirectEntryPrivateKeySource) ssh_with_passphrase.getPrivateKeySource();
    assertThat(source.getPrivateKey().getPlainText(), equalTo("s3cr3t"));
}
Also used : Jenkins(jenkins.model.Jenkins) LDAPSecurityRealm(hudson.security.LDAPSecurityRealm) DirectEntryPrivateKeySource(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource) GitTool(hudson.plugins.git.GitTool) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

GitTool (hudson.plugins.git.GitTool)2 Jenkins (jenkins.model.Jenkins)2 Test (org.junit.Test)2 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)1 DirectEntryPrivateKeySource (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.DirectEntryPrivateKeySource)1 DockerCloud (com.nirima.jenkins.plugins.docker.DockerCloud)1 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)1 LDAPSecurityRealm (hudson.security.LDAPSecurityRealm)1 Mailer (hudson.tasks.Mailer)1 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)1 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)1 LibraryConfiguration (org.jenkinsci.plugins.workflow.libs.LibraryConfiguration)1 ArtifactoryBuilder (org.jfrog.hudson.ArtifactoryBuilder)1 JFrogPlatformInstance (org.jfrog.hudson.JFrogPlatformInstance)1