Search in sources :

Example 1 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class GiteaOrganisationFolderTest method configure_gitea_organisation_folder_seed_job.

@Test
@WithPlugin({ "branch-api.jpi", "cloudbees-folder.jpi", "scm-api.jpi", "structs.jpi" })
@ConfiguredWithCode("SeedJobTest_withGiteaOrganisation.yml")
public void configure_gitea_organisation_folder_seed_job() {
    OrganizationFolder folder = (OrganizationFolder) r.jenkins.getItem("Gitea Organization Folder");
    assertNotNull(folder);
    GiteaSCMNavigator organization = (GiteaSCMNavigator) folder.getNavigators().get(0);
    assertNotNull(organization);
    assertEquals("gitea-token", organization.getCredentialsId());
    assertEquals("https://git.example.com", organization.getServerUrl());
    assertEquals("OWN", organization.getRepoOwner());
    List<SCMTrait<?>> traits = organization.getTraits();
    assertEquals(7, traits.size());
    assertEquals(ExcludeArchivedRepositoriesTrait.class, traits.get(0).getClass());
    assertEquals(TagDiscoveryTrait.class, traits.get(1).getClass());
    SCMTrait<?> trait2 = traits.get(2);
    assertEquals(BranchDiscoveryTrait.class, trait2.getClass());
    assertEquals(1, ((BranchDiscoveryTrait) trait2).getStrategyId());
    SCMTrait<?> trait3 = traits.get(3);
    assertEquals(OriginPullRequestDiscoveryTrait.class, trait3.getClass());
    assertEquals(2, ((OriginPullRequestDiscoveryTrait) trait3).getStrategyId());
    SCMTrait<?> trait4 = traits.get(4);
    assertEquals(ForkPullRequestDiscoveryTrait.class, trait4.getClass());
    assertEquals(1, ((ForkPullRequestDiscoveryTrait) trait4).getStrategyId());
    assertEquals(ForkPullRequestDiscoveryTrait.TrustContributors.class, ((ForkPullRequestDiscoveryTrait) trait4).getTrust().getClass());
    SCMTrait<?> trait5 = traits.get(5);
    assertEquals(WebhookRegistrationTrait.class, trait5.getClass());
    assertEquals("ITEM", ((WebhookRegistrationTrait) trait5).getMode().name());
    SCMTrait<?> trait6 = traits.get(6);
    assertEquals(SSHCheckoutTrait.class, trait6.getClass());
    assertEquals("ssh-gitea", ((SSHCheckoutTrait) trait6).getCredentialsId());
}
Also used : ForkPullRequestDiscoveryTrait(org.jenkinsci.plugin.gitea.ForkPullRequestDiscoveryTrait) OrganizationFolder(jenkins.branch.OrganizationFolder) WebhookRegistrationTrait(org.jenkinsci.plugin.gitea.WebhookRegistrationTrait) GiteaSCMNavigator(org.jenkinsci.plugin.gitea.GiteaSCMNavigator) SCMTrait(jenkins.scm.api.trait.SCMTrait) Test(org.junit.Test) WithPlugin(org.jvnet.hudson.test.recipes.WithPlugin) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 2 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class CredentialsTest method testExportFileCredentials.

@Test
@ConfiguredWithCode("GlobalCredentials.yml")
public void testExportFileCredentials() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CredentialsRootConfigurator root = ExtensionList.lookupSingleton(CredentialsRootConfigurator.class);
    CNode node = root.describe(root.getTargetComponent(context), context);
    assertNotNull(node);
    final Mapping mapping = node.asMapping();
    Mapping fileCredential = mapping.get("system").asMapping().get("domainCredentials").asSequence().get(0).asMapping().get("credentials").asSequence().get(2).asMapping().get("file").asMapping();
    assertThat(fileCredential.getScalarValue("scope"), is("GLOBAL"));
    assertThat(fileCredential.getScalarValue("id"), is("secret-file"));
    assertThat(fileCredential.getScalarValue("fileName"), is("mysecretfile.txt"));
    assertThat(fileCredential.getScalarValue("secretBytes"), not("WJjZAo="));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) CredentialsRootConfigurator(com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 3 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class CustomToolsTest method configure_custom_tools.

@Test
@Issue("#97")
@Ignore
@ConfiguredWithCode(value = "CustomToolsTest.yml")
public void configure_custom_tools() {
    DescriptorImpl descriptor = (DescriptorImpl) j.jenkins.getDescriptorOrDie(CustomTool.class);
    assertEquals(1, descriptor.getInstallations().length);
    final CustomTool customTool = descriptor.getInstallations()[0];
    final InstallSourceProperty source = customTool.getProperties().get(InstallSourceProperty.class);
    assertNotNull(source);
    final CommandInstaller installer = source.installers.get(CommandInstaller.class);
    assertNotNull(installer);
    assertEquals("/bin/my-tool", installer.getToolHome());
}
Also used : CustomTool(com.cloudbees.jenkins.plugins.customtools.CustomTool) DescriptorImpl(com.cloudbees.jenkins.plugins.customtools.CustomTool.DescriptorImpl) CommandInstaller(hudson.tools.CommandInstaller) InstallSourceProperty(hudson.tools.InstallSourceProperty) Ignore(org.junit.Ignore) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 4 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class GlobalLibrariesTest method configure_global_library_using_github.

@Issue("JENKINS-57557")
@Test
@ConfiguredWithCode("GlobalLibrariesGitHubTest.yml")
public void configure_global_library_using_github() {
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("jenkins-pipeline-lib", library.getName());
    final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
    final GitHubSCMSource scm = (GitHubSCMSource) retriever.getScm();
    assertEquals("e43d6600-ba0e-46c5-8eae-3989bf654055", scm.getId());
    assertEquals("jenkins-infra", scm.getRepoOwner());
    assertEquals("pipeline-library", scm.getRepository());
    assertEquals(3, scm.getTraits().size());
    final BranchDiscoveryTrait branchDiscovery = (BranchDiscoveryTrait) scm.getTraits().get(0);
    assertEquals(1, branchDiscovery.getStrategyId());
    final OriginPullRequestDiscoveryTrait prDiscovery = (OriginPullRequestDiscoveryTrait) scm.getTraits().get(1);
    assertEquals(2, prDiscovery.getStrategyId());
    final ForkPullRequestDiscoveryTrait forkDiscovery = (ForkPullRequestDiscoveryTrait) scm.getTraits().get(2);
    assertEquals(3, forkDiscovery.getStrategyId());
    assertThat(forkDiscovery.getTrust(), instanceOf(TrustPermission.class));
}
Also used : ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) SCMSourceRetriever(org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) TrustPermission(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait.TrustPermission) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 5 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode 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)

Aggregations

ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)52 Test (org.junit.Test)51 Issue (org.jvnet.hudson.test.Issue)18 CNode (io.jenkins.plugins.casc.model.CNode)16 Jenkins (jenkins.model.Jenkins)15 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)8 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)8 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)8 Mapping (io.jenkins.plugins.casc.model.Mapping)7 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)5 Configurator (io.jenkins.plugins.casc.Configurator)5 ProxyConfiguration (hudson.ProxyConfiguration)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)3 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)2 FreeStyleProject (hudson.model.FreeStyleProject)2 User (hudson.model.User)2