Java Code Examples for jenkins.model.Jenkins#createProject()

The following examples show how to use jenkins.model.Jenkins#createProject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FreestyleTest.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
@Override
public Boolean call() throws Throwable {
    final Jenkins jenkins = Jenkins.getInstance();

    // prepare job
    final FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "freestyle-project");
    final Shell env = new Shell("env");
    project.getBuildersList().add(env);
    project.setAssignedLabel(new LabelAtom(DOCKER_CLOUD_LABEL));
    project.save();

    LOG.trace("trace test.");
    project.scheduleBuild(new TestCause());

    // image pull may take time
    waitUntilNoActivityUpTo(jenkins, 10 * 60 * 1000);

    final FreeStyleBuild lastBuild = project.getLastBuild();
    assertThat(lastBuild, not(nullValue()));
    assertThat(lastBuild.getResult(), is(Result.SUCCESS));

    assertThat(getLog(lastBuild), Matchers.containsString(TEST_VALUE));
    assertThat(getLog(lastBuild), Matchers.containsString(CLOUD_ID + "=" + DOCKER_CLOUD_NAME));

    return true;
}
 
Example 2
Source File: FreestyleTest.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
@Override
        public Boolean call() throws Throwable {
            final Jenkins jenkins = Jenkins.getInstance();
            assertThat(image, notNullValue());

            // prepare job
            final FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "freestyle-dockerShell");
            final Shell env = new Shell("env");
            project.getBuildersList().add(env);

            DockerShellStep dockerShellStep = new DockerShellStep();
            dockerShellStep.setShellScript("env && pwd");
            dockerShellStep.getContainerLifecycle().setImage(image);
            dockerShellStep.setConnector(new CloudNameDockerConnector(DOCKER_CLOUD_NAME));
            project.getBuildersList().add(dockerShellStep);

//            project.setAssignedLabel(new LabelAtom(DOCKER_CLOUD_LABEL));
            project.save();

            LOG.trace("trace test.");
            project.scheduleBuild(new TestCause());

            // image pull may take time
            waitUntilNoActivityUpTo(jenkins, 10 * 60 * 1000);

            final FreeStyleBuild lastBuild = project.getLastBuild();
            assertThat(lastBuild, not(nullValue()));
            assertThat(lastBuild.getResult(), is(Result.SUCCESS));

            assertThat(getLog(lastBuild), Matchers.containsString("exit code: 0"));

            return true;
        }
 
Example 3
Source File: FolderRoleBenchmark.java    From folder-auth-plugin with MIT License 4 votes vote down vote up
@Override
public void setup() throws Exception {
    Jenkins jenkins = getJenkins();
    jenkins.setSecurityRealm(new JenkinsRule().createDummySecurityRealm());

    Set<GlobalRole> globalRoles = ImmutableSet.of((
            new GlobalRole("ADMIN", wrapPermissions(Jenkins.ADMINISTER), Collections.singleton("admin"))),
        new GlobalRole("read", wrapPermissions(Jenkins.READ), Collections.singleton("authenticated"))
    );

    Set<FolderRole> folderRoles = new HashSet<>();

    Random random = new Random(100L);

    // create the folders
    for (int i = 0; i < 10; i++) {
        String topFolderName = "TopFolder" + i;
        Folder folder = jenkins.createProject(Folder.class, topFolderName);

        Set<String> users = new HashSet<>();
        for (int k = 0; k < random.nextInt(5); k++) {
            users.add("user" + random.nextInt(100));
        }

        FolderRole userRole = new FolderRole(topFolderName, wrapPermissions(Item.READ, Item.DISCOVER),
            Collections.singleton(topFolderName), users);

        folderRoles.add(userRole);

        for (int j = 0; j < 5; j++) {
            Folder bottom = folder.createProject(Folder.class, "BottomFolder" + j);

            Set<String> maintainers = new HashSet<>(2);
            maintainers.add("user" + random.nextInt(100));
            maintainers.add("user" + random.nextInt(100));

            FolderRole maintainerRole = new FolderRole(bottom.getFullName(),
                wrapPermissions(Item.READ, Item.DISCOVER, Item.CREATE),
                Collections.singleton(topFolderName), maintainers);

            Set<String> admin = Collections.singleton("user" + random.nextInt(100));

            FolderRole folderAdminRole = new FolderRole(bottom.getFullName(), wrapPermissions(Item.READ, Item.DISCOVER,
                Item.CONFIGURE, Item.CREATE), Collections.singleton(topFolderName), admin);
            folderRoles.add(maintainerRole);
            folderRoles.add(folderAdminRole);

            for (int k = 0; k < 5; k++) {
                bottom.createProject(FreeStyleProject.class, "Project" + k);
            }
        }
    }

    jenkins.setAuthorizationStrategy(new FolderBasedAuthorizationStrategy(globalRoles, folderRoles,
        Collections.emptySet()));
}
 
Example 4
Source File: FolderBasedAuthorizationStrategyTest.java    From folder-auth-plugin with MIT License 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    Jenkins jenkins = jenkinsRule.jenkins;
    jenkins.setSecurityRealm(jenkinsRule.createDummySecurityRealm());

    FolderBasedAuthorizationStrategy strategy = new FolderBasedAuthorizationStrategy(Collections.emptySet(),
            Collections.emptySet(), Collections.emptySet());
    jenkins.setAuthorizationStrategy(strategy);

    final String adminRoleName = "adminRole";
    final String overallReadRoleName = "overallRead";

    FolderAuthorizationStrategyAPI.addGlobalRole(new GlobalRole(adminRoleName,
            wrapPermissions(FolderAuthorizationStrategyManagementLink.getSafePermissions(
                    new HashSet<>(PermissionGroup.getAll())))));

    FolderAuthorizationStrategyAPI.assignSidToGlobalRole("admin", adminRoleName);

    FolderAuthorizationStrategyAPI.addGlobalRole(new GlobalRole(overallReadRoleName, wrapPermissions(Permission.READ)));
    FolderAuthorizationStrategyAPI.assignSidToGlobalRole("authenticated", overallReadRoleName);

    FolderAuthorizationStrategyAPI.addFolderRole(new FolderRole("folderRole1", wrapPermissions(Item.READ),
            ImmutableSet.of("root")));
    FolderAuthorizationStrategyAPI.assignSidToFolderRole("user1", "folderRole1");
    FolderAuthorizationStrategyAPI.assignSidToFolderRole("user2", "folderRole1");

    FolderAuthorizationStrategyAPI.addFolderRole(new FolderRole("folderRole2", wrapPermissions(Item.CONFIGURE, Item.DELETE),
            ImmutableSet.of("root/child1")));
    FolderAuthorizationStrategyAPI.assignSidToFolderRole("user2", "folderRole2");

    /*
     * Folder hierarchy for the test
     *
     *             root
     *             /  \
     *        child1   child2
     *          /        \
     *        child3     job1
     *         /
     *        job2
     */

    root = jenkins.createProject(Folder.class, "root");
    child1 = root.createProject(Folder.class, "child1");
    child2 = root.createProject(Folder.class, "child2");
    child3 = child1.createProject(Folder.class, "child3");

    job1 = child2.createProject(FreeStyleProject.class, "job1");
    job2 = child3.createProject(FreeStyleProject.class, "job2");

    admin = User.getById("admin", true);
    user1 = User.getById("user1", true);
    user2 = User.getById("user2", true);
}