Search in sources :

Example 1 with LibraryConfiguration

use of org.jenkinsci.plugins.workflow.libs.LibraryConfiguration 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 2 with LibraryConfiguration

use of org.jenkinsci.plugins.workflow.libs.LibraryConfiguration 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 LibraryConfiguration

use of org.jenkinsci.plugins.workflow.libs.LibraryConfiguration in project configuration-as-code-plugin by jenkinsci.

the class GlobalLibrariesTest method configure_global_library.

@Test
@ConfiguredWithCode("GlobalLibrariesTest.yml")
public void configure_global_library() throws Exception {
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("awesome-lib", library.getName());
    final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
    final GitSCMSource scm = (GitSCMSource) retriever.getScm();
    assertEquals("https://github.com/jenkins-infra/pipeline-library.git", scm.getRemote());
}
Also used : SCMSourceRetriever(org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitSCMSource(jenkins.plugins.git.GitSCMSource) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 4 with LibraryConfiguration

use of org.jenkinsci.plugins.workflow.libs.LibraryConfiguration in project configuration-as-code-plugin by jenkinsci.

the class GitTest method checkAssemblaWebIsLoaded.

@Test
@Issue("JENKINS-57604")
@ConfiguredWithCode("GitTest.yml")
public void checkAssemblaWebIsLoaded() {
    final Jenkins jenkins = Jenkins.get();
    final GlobalLibraries libs = jenkins.getExtensionList(GlobalConfiguration.class).get(GlobalLibraries.class);
    LibraryConfiguration lib = libs.getLibraries().get(0);
    SCMRetriever retriever = (SCMRetriever) lib.getRetriever();
    GitSCM scm = (GitSCM) retriever.getScm();
    AssemblaWeb browser = (AssemblaWeb) scm.getBrowser();
    assertEquals("assembla.acmecorp.com", browser.getRepoUrl());
}
Also used : Jenkins(jenkins.model.Jenkins) GlobalConfiguration(jenkins.model.GlobalConfiguration) AssemblaWeb(hudson.plugins.git.browser.AssemblaWeb) GlobalLibraries(org.jenkinsci.plugins.workflow.libs.GlobalLibraries) SCMRetriever(org.jenkinsci.plugins.workflow.libs.SCMRetriever) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitSCM(hudson.plugins.git.GitSCM) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 5 with LibraryConfiguration

use of org.jenkinsci.plugins.workflow.libs.LibraryConfiguration in project configuration-as-code-plugin by jenkinsci.

the class WorkflowCpsGlobalLibTest method configure_global_library.

@Test
@ConfiguredWithReadme("workflow-cps-global-lib/README.md")
public void configure_global_library() {
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("awesome-lib", library.getName());
    final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
    final GitSCMSource scm = (GitSCMSource) retriever.getScm();
    assertEquals("https://github.com/jenkins-infra/pipeline-library.git", scm.getRemote());
}
Also used : SCMSourceRetriever(org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever) LibraryConfiguration(org.jenkinsci.plugins.workflow.libs.LibraryConfiguration) GitSCMSource(jenkins.plugins.git.GitSCMSource) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

LibraryConfiguration (org.jenkinsci.plugins.workflow.libs.LibraryConfiguration)5 Test (org.junit.Test)5 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)3 SCMSourceRetriever (org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever)3 Jenkins (jenkins.model.Jenkins)2 GitSCMSource (jenkins.plugins.git.GitSCMSource)2 Issue (org.jvnet.hudson.test.Issue)2 DockerCloud (com.nirima.jenkins.plugins.docker.DockerCloud)1 GitSCM (hudson.plugins.git.GitSCM)1 GitTool (hudson.plugins.git.GitTool)1 AssemblaWeb (hudson.plugins.git.browser.AssemblaWeb)1 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)1 Mailer (hudson.tasks.Mailer)1 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)1 GlobalConfiguration (jenkins.model.GlobalConfiguration)1 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)1 BranchDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait)1 ForkPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait)1 TrustPermission (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait.TrustPermission)1 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)1