Java Code Examples for hudson.model.FreeStyleProject#save()

The following examples show how to use hudson.model.FreeStyleProject#save() . 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: CucumberLivingDocumentationIT.java    From cucumber-living-documentation-plugin with MIT License 6 votes vote down vote up
@Test
public void shouldGenerateLivingDocumentatationOnSlaveNode() throws Exception{
	DumbSlave slave = jenkins.createOnlineSlave();
	FreeStyleProject project = jenkins.createFreeStyleProject("test");
	project.setAssignedNode(slave);
	
	SingleFileSCM scm = new SingleFileSCM("asciidoctor.json",
			CucumberLivingDocumentationIT.class.getResource("/json-output/asciidoctor/asciidoctor.json").toURI().toURL());
	
	project.setScm(scm);
	CukedoctorPublisher publisher = new CukedoctorPublisher(null, FormatType.HTML, TocType.RIGHT, true, true, "Living Documentation",false,false,false,false,false);
	project.getPublishersList().add(publisher);
	project.save();

	FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
	jenkins.assertLogContains("Format: html" + NEW_LINE + "Toc: right"+NEW_LINE +
			"Title: Living Documentation"+NEW_LINE+"Numbered: true"+NEW_LINE +
			"Section anchors: true", build);
	jenkins.assertLogContains("Found 4 feature(s)...",build);
	jenkins.assertLogContains("Documentation generated successfully!",build);
	Assert.assertTrue("It should run on slave",build.getBuiltOn().equals(slave));
	
}
 
Example 2
Source File: CucumberLivingDocumentationIT.java    From cucumber-living-documentation-plugin with MIT License 6 votes vote down vote up
@Test
public void shouldGenerateLivingDocumentatation() throws Exception{
	//given
	FreeStyleProject project = jenkins.createFreeStyleProject("test");
	SingleFileSCM scm = new SingleFileSCM("asciidoctor.json",
			CucumberLivingDocumentationIT.class.getResource("/json-output/asciidoctor/asciidoctor.json").toURI().toURL());
	
	project.setScm(scm);
	CukedoctorPublisher publisher = new CukedoctorPublisher(null, FormatType.HTML, TocType.RIGHT, true, true, "Living Documentation",false,false,false,false,false);
	project.getPublishersList().add(publisher);
	project.save();

	//when
	FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
	
	//then
	jenkins.assertLogContains("Format: html" + NEW_LINE + "Toc: right"+NEW_LINE +
			"Title: Living Documentation"+NEW_LINE+"Numbered: true"+NEW_LINE +
			"Section anchors: true", build);
	jenkins.assertLogContains("Found 4 feature(s)...",build);
	jenkins.assertLogContains("Documentation generated successfully!",build);
	
}
 
Example 3
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 4
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 5
Source File: AWSDeviceFarmRecorderTest.java    From aws-device-farm-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
@Issue("JENKINS-50483")
public void dataSerializationSmokeTest() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    AWSDeviceFarmRecorder rec = new AWSDeviceFarmRecorder(
            "TestProjectName", "TestDevicePool", null, null,
            null, null, "APPIUM_JAVA_JUNIT", false, false, null,
            null, null, null, null, null, null,
            null, null, null, null, null, null, null, null,
            null, null, null, null, null, null,
            null, null, null, null, false, false,
            null, null, null, null, null, null,
            false, false, false, 10, false, false,
            false, false, false, null
    );
    p.getPublishersList().add(rec);

    // Try to build it. It is not supposed to work, but we will filter out the JEP-200 exception
    final QueueTaskFuture<FreeStyleBuild> future = p.scheduleBuild2(0);
    final FreeStyleBuild build = future.get();
    j.assertBuildStatus(Result.FAILURE, build);
    // Currently it fails with Either IAM Role ARN or AKID/SKID must be set and does not report the serialization issue after that

    // No matter what, we should be able to save the project even after the failure
    p.save();
    build.save();
}
 
Example 6
Source File: AbortRunningJobRunnerCauseTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
@RandomlyFails(value = "No idea why it doesn't work normally")
public void testAbortRunningFreestyleProject() throws Exception {

    MockFolder folder = j.createFolder("freestyle_folder");

    FreeStyleProject job1 = folder.createProject(FreeStyleProject.class, "project1");
    job1.setDisplayName("project1 display name");
    job1.setConcurrentBuild(true);
    job1.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job1);
    job1.save();

    FreeStyleProject job2 = folder.createProject(FreeStyleProject.class, "project2");
    job2.setDisplayName("project1 display name");
    job2.setConcurrentBuild(true);
    job2.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job2);
    job2.save();

    FreeStyleProject job3 = folder.createProject(FreeStyleProject.class, "project3");
    job3.setDisplayName("project1 display name");
    job3.setConcurrentBuild(true);
    job3.getBuildersList().add(new SleepBuilder());
    configRoundTripUnsecure(job3);
    job3.save();

    testAbortRunning(job1, job2, job3);
}
 
Example 7
Source File: FreeStyleProjectTest.java    From lockable-resources-plugin with MIT License 4 votes vote down vote up
@Test
public void migrateToScript() throws Exception {
  LockableResourcesManager.get().createResource("resource1");

  FreeStyleProject p = j.createFreeStyleProject("p");
  p.addProperty(
      new RequiredResourcesProperty(
          null, null, null, "groovy:resourceName == 'resource1'", null));

  p.save();

  j.jenkins.reload();

  FreeStyleProject p2 = j.jenkins.getItemByFullName("p", FreeStyleProject.class);
  RequiredResourcesProperty newProp = p2.getProperty(RequiredResourcesProperty.class);
  assertNull(newProp.getLabelName());
  assertNotNull(newProp.getResourceMatchScript());
  assertEquals("resourceName == 'resource1'", newProp.getResourceMatchScript().getScript());

  SemaphoreBuilder p2Builder = new SemaphoreBuilder();
  p2.getBuildersList().add(p2Builder);

  FreeStyleProject p3 = j.createFreeStyleProject("p3");
  p3.addProperty(new RequiredResourcesProperty("resource1", null, "1", null, null));
  SemaphoreBuilder p3Builder = new SemaphoreBuilder();
  p3.getBuildersList().add(p3Builder);

  final QueueTaskFuture<FreeStyleBuild> taskA =
      p3.scheduleBuild2(0, new TimerTrigger.TimerTriggerCause());
  TestHelpers.waitForQueue(j.jenkins, p3);
  final QueueTaskFuture<FreeStyleBuild> taskB =
      p2.scheduleBuild2(0, new TimerTrigger.TimerTriggerCause());

  p3Builder.release();
  final FreeStyleBuild buildA = taskA.get(60, TimeUnit.SECONDS);
  p2Builder.release();
  final FreeStyleBuild buildB = taskB.get(60, TimeUnit.SECONDS);

  long buildAEndTime = buildA.getStartTimeInMillis() + buildA.getDuration();
  assertTrue(
      "Project A build should be finished before the build of project B starts. "
          + "A finished at "
          + buildAEndTime
          + ", B started at "
          + buildB.getStartTimeInMillis(),
      buildB.getStartTimeInMillis() >= buildAEndTime);
}
 
Example 8
Source File: GitHubBranchTriggerTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@LocalData
@Test
public void someTest() throws Exception {
    FreeStyleProject prj = jRule.createFreeStyleProject("project");
    prj.addProperty(new GithubProjectProperty("http://localhost/org/repo"));

    final List<GitHubBranchEvent> events = new ArrayList<>();
    events.add(new GitHubBranchCreatedEvent());
    events.add(new GitHubBranchHashChangedEvent());

    final GitHubBranchTrigger trigger = new GitHubBranchTrigger("", CRON, events);
    prj.addTrigger(trigger);
    prj.save();
    // activate trigger
    jRule.configRoundtrip(prj);

    final GitHubBranchTrigger branchTrigger = prj.getTrigger(GitHubBranchTrigger.class);

    assertThat(branchTrigger.getRemoteRepository(), notNullValue());

    GitHubBranchRepository localRepo = prj.getAction(GitHubBranchRepository.class);
    assertThat(localRepo, notNullValue());
    assertThat(localRepo.getBranches().size(), is(2));
    assertThat(localRepo.getBranches(), hasKey("for-removal"));
    assertThat(localRepo.getBranches(), hasKey("should-change"));
    GitHubBranch shouldChange = localRepo.getBranches().get("should-change");
    assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffbb"));

    // only single branch should change in local repo
    branchTrigger.doRun("should-change");
    jRule.waitUntilNoActivity();

    assertThat(prj.getBuilds(), hasSize(1));
    FreeStyleBuild lastBuild = prj.getLastBuild();

    GitHubBranchCause cause = lastBuild.getCause(GitHubBranchCause.class);
    assertThat(cause, notNullValue());
    assertThat(cause.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg"));
    assertThat(cause.getBranchName(), is("should-change"));

    localRepo = prj.getAction(GitHubBranchRepository.class);
    assertThat(localRepo, notNullValue());
    assertThat(localRepo.getBranches().size(), is(2));
    assertThat(localRepo.getBranches(), hasKey("for-removal"));
    assertThat(localRepo.getBranches(), hasKey("should-change"));
    shouldChange = localRepo.getBranches().get("should-change");
    assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg"));


    // and now full trigger run()
    branchTrigger.doRun();

    jRule.waitUntilNoActivity();

    assertThat(prj.getBuilds(), hasSize(2));
    lastBuild = prj.getLastBuild();
    assertThat(lastBuild, notNullValue());

    cause = lastBuild.getCause(GitHubBranchCause.class);
    assertThat(cause, notNullValue());
    assertThat(cause.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e"));
    assertThat(cause.getBranchName(), is("new-branch"));

    localRepo = prj.getAction(GitHubBranchRepository.class);
    assertThat(localRepo.getBranches().size(), is(2));
    assertThat(localRepo.getBranches(), not(hasKey("for-removal")));
    assertThat(localRepo.getBranches(), hasKey("should-change"));

    shouldChange = localRepo.getBranches().get("should-change");
    assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg"));

    assertThat(localRepo.getBranches(), hasKey("new-branch"));
    GitHubBranch branch = localRepo.getBranches().get("new-branch");
    assertThat(branch.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e"));

}
 
Example 9
Source File: GitHubBranchTriggerJRuleTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
/**
 * Ensure that GitHubPRRepository can be created without remote connections.
 */
@Test
public void repositoryInitialisationWhenProviderFails() throws Exception {
    final FreeStyleProject project = jRule.createProject(FreeStyleProject.class, "project");

    project.addProperty(new GithubProjectProperty("https://github.com/KostyaSha/test-repo/"));

    final GitHubBranchTrigger trigger = new GitHubBranchTrigger("", HEAVY_HOOKS, emptyList());
    trigger.setRepoProvider(new FailingGitHubRepoProvider());
    project.addTrigger(trigger);

    project.save();

    final FreeStyleProject freeStyleProject = (FreeStyleProject) jRule.getInstance().getItem("project");

    final GitHubBranchRepository repository = freeStyleProject.getAction(GitHubBranchRepository.class);

    assertThat(repository, notNullValue());
}
 
Example 10
Source File: GitHubPRTriggerMockTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
/**
 * loading old local state data, running trigger and checking that old disappeared and new appeared
 */
@LocalData
@Test
public void actualiseRepo() throws Exception {
    Thread.sleep(1000);

    FreeStyleProject project = (FreeStyleProject) jRule.getInstance().getItem("project");
    assertThat(project, notNullValue());

    GitHubPRTrigger trigger = project.getTrigger(GitHubPRTrigger.class);
    assertThat(trigger, notNullValue());

    GitHubRepositoryName repoFullName = trigger.getRepoFullName();
    assertThat(repoFullName.getHost(), is("localhost"));
    assertThat(repoFullName.getUserName(), is("org"));
    assertThat(repoFullName.getRepositoryName(), is("old-repo"));

    GitHubPRRepository prRepository = project.getAction(GitHubPRRepository.class);
    assertThat(project, notNullValue());

    assertThat(prRepository.getFullName(), is("org/old-repo"));
    assertThat(prRepository.getGithubUrl(), notNullValue());
    assertThat(prRepository.getGithubUrl().toString(), is("https://localhost/org/old-repo/"));
    assertThat(prRepository.getGitUrl(), is("git://localhost/org/old-repo.git"));
    assertThat(prRepository.getSshUrl(), is("git@localhost:org/old-repo.git"));

    final Map<Integer, GitHubPRPullRequest> pulls = prRepository.getPulls();
    assertThat(pulls.size(), is(1));

    final GitHubPRPullRequest pullRequest = pulls.get(1);
    assertThat(pullRequest, notNullValue());
    assertThat(pullRequest.getNumber(), is(1));
    assertThat(pullRequest.getHeadSha(), is("65d0f7818009811e5d5eb703ebad38bbcc816b49"));
    assertThat(pullRequest.isMergeable(), is(true));
    assertThat(pullRequest.getBaseRef(), is("master"));
    assertThat(pullRequest.getHtmlUrl().toString(), is("https://localhost/org/old-repo/pull/1"));

    // now new
    project.addProperty(new GithubProjectProperty("http://localhost/org/repo"));

    GitHubPluginRepoProvider repoProvider = new GitHubPluginRepoProvider();
    repoProvider.setManageHooks(false);
    repoProvider.setRepoPermission(GHPermission.PULL);

    trigger.setRepoProvider(repoProvider);
    project.addTrigger(trigger);
    project.save();

    // activate trigger
    jRule.configRoundtrip(project);

    trigger = ghPRTriggerFromJob(project);

    trigger.doRun();

    jRule.waitUntilNoActivity();

    assertThat(project.getBuilds(), hasSize(1));

    repoFullName = trigger.getRepoFullName();
    assertThat(repoFullName.getHost(), Matchers.is("localhost"));
    assertThat(repoFullName.getUserName(), Matchers.is("org"));
    assertThat(repoFullName.getRepositoryName(), Matchers.is("repo"));


    GitHubPRPollingLogAction logAction = project.getAction(GitHubPRPollingLogAction.class);
    assertThat(logAction, notNullValue());
    assertThat(logAction.getLog(),
            containsString("Repository full name changed from 'org/old-repo' to 'org/repo'.\n"));

    assertThat(logAction.getLog(),
            containsString("Changing GitHub url from 'https://localhost/org/old-repo/' " +
                    "to 'http://localhost/org/repo'.\n"));
    assertThat(logAction.getLog(),
            containsString("Changing Git url from 'git://localhost/org/old-repo.git' " +
                    "to 'git://localhost/org/repo.git'.\n"));
    assertThat(logAction.getLog(),
            containsString("Changing SSH url from 'git@localhost:org/old-repo.git' " +
                    "to 'git@localhost:org/repo.git'.\n"));
    assertThat(logAction.getLog(),
            containsString("Local settings changed, removing PRs in repository!"));

}
 
Example 11
Source File: GitHubPRTriggerJRuleTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
/**
 * Ensure that GitHubPRRepository can be created without remote connections.
 */
@Test
public void repositoryInitialisationWhenProviderFails() throws Exception {
    final FreeStyleProject project = jRule.createProject(FreeStyleProject.class, "project");

    project.addProperty(new GithubProjectProperty("https://github.com/KostyaSha/test-repo/"));

    final GitHubPRTrigger prTrigger = new GitHubPRTrigger("", HEAVY_HOOKS, emptyList());
    prTrigger.setRepoProvider(new GitHubBranchTriggerJRuleTest.FailingGitHubRepoProvider());
    project.addTrigger(prTrigger);

    project.save();

    final FreeStyleProject freeStyleProject = (FreeStyleProject) jRule.getInstance().getItem("project");

    final GitHubPRRepository repository = freeStyleProject.getAction(GitHubPRRepository.class);

    assertThat(repository, notNullValue());
}
 
Example 12
Source File: FreestyleITest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Test
public void freestyleTest() throws Exception {
    // create job
    FreeStyleProject job = jRule.createFreeStyleProject("freestyle-job");

    job.addProperty(getPreconfiguredProperty(ghRule.getGhRepo()));

    job.addTrigger(getPreconfiguredPRTrigger());

    job.getBuildersList().add(new GitHubPRStatusBuilder());
    job.getBuildersList().add(new Shell("sleep 10"));

    job.getPublishersList().add(new GitHubPRBuildStatusPublisher());
    job.getPublishersList().add(new GitHubPRCommentPublisher(new GitHubPRMessage("Comment"), null, null));

    job.save();

    super.basicTest(job);
}
 
Example 13
Source File: DockerBuildImageStepTest.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
@Test
    public void testBuild() throws Throwable {
        jRule.getInstance().setNumExecutors(0);
//        jRule.createSlave();
//        jRule.createSlave("my-slave", "remote-slave", new EnvVars());
        final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
                null, "description", "vagrant", "vagrant");

        CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next();
        store.addCredentials(Domain.global(), credentials);

        final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(),
                "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts
                "", //      String javaPath,
                "",  //      String prefixStartSlaveCmd,
                "", //      String suffixStartSlaveCmd,
                20, //      Integer launchTimeoutSeconds,
                1, //      Integer maxNumRetries,
                3,//      Integer retryWaitTime
                new NonVerifyingKeyVerificationStrategy()
        );
        final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher);
        jRule.getInstance().addNode(dumbSlave);
        await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue()));
        String dockerfilePath = dumbSlave.getChannel().call(new StringThrowableCallable());


        final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector()
                .withConnectorType(JERSEY)
                .withServerUrl("tcp://127.0.0.1:2376")
                .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys"))
                ;
//                .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "",
//                        "/home/vagrant/keys"));

        DockerBuildImage buildImage = new DockerBuildImage();
        buildImage.setBaseDirectory(dockerfilePath);
        buildImage.setPull(true);
        buildImage.setNoCache(true);

        DockerBuildImageStep dockerBuildImageStep = new DockerBuildImageStep(dockerConnector, buildImage);

        FreeStyleProject project = jRule.createFreeStyleProject("test");
        project.getBuildersList().add(dockerBuildImageStep);

        project.save();

        QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);
        FreeStyleBuild freeStyleBuild = taskFuture.get();
        jRule.waitForCompletion(freeStyleBuild);
        jRule.assertBuildStatusSuccess(freeStyleBuild);
    }
 
Example 14
Source File: DockerImageComboStepTest.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
@Ignore
    @Test
    public void testComboBuild() throws Throwable {
        jRule.getInstance().setNumExecutors(0);
//        jRule.createSlave();
//        jRule.createSlave("my-slave", "remote-slave", new EnvVars());
        final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
                null, "description", "vagrant", "vagrant");

        CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next();
        store.addCredentials(Domain.global(), credentials);

        final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(),
                "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts
                "", //      String javaPath,
                "",  //      String prefixStartSlaveCmd,
                "", //      String suffixStartSlaveCmd,
                20, //      Integer launchTimeoutSeconds,
                1, //      Integer maxNumRetries,
                3,//      Integer retryWaitTime
                new NonVerifyingKeyVerificationStrategy()
        );
        final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher);
        jRule.getInstance().addNode(dumbSlave);
        await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue()));
        String dockerfilePath = dumbSlave.getChannel().call(new StringThrowableCallable());


        final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector()
                .withConnectorType(JERSEY)
                .withServerUrl("tcp://127.0.0.1:2376")
                .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys"));
//                .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "",
//                        "/home/vagrant/keys"));

        DockerBuildImage buildImage = new DockerBuildImage();
        buildImage.setBaseDirectory(dockerfilePath);
        buildImage.setPull(true);
        buildImage.setTags(Collections.singletonList("localhost:5000/myfirstimage"));

        DockerImageComboStep comboStep = new DockerImageComboStep(dockerConnector, buildImage);
        comboStep.setClean(true);
        comboStep.setCleanupDangling(true);
        comboStep.setPush(true);

        FreeStyleProject project = jRule.createFreeStyleProject("test");
        project.getBuildersList().add(comboStep);

        project.save();

        QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);
        FreeStyleBuild freeStyleBuild = taskFuture.get();
        jRule.waitForCompletion(freeStyleBuild);
        jRule.assertBuildStatusSuccess(freeStyleBuild);
    }
 
Example 15
Source File: DockerShellStepIT.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
@Test
    public void testDockerShellStep() throws Throwable {
        jRule.getInstance().setNumExecutors(0);
//        jRule.createSlave();
//        jRule.createSlave("my-slave", "remote-slave", new EnvVars());
        final UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM,
                null, "description", "vagrant", "vagrant");

        CredentialsStore store = CredentialsProvider.lookupStores(jRule.getInstance()).iterator().next();
        store.addCredentials(Domain.global(), credentials);

        final SSHLauncher sshLauncher = new SSHLauncher("192.168.33.10", 22, credentials.getId(),
                "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", //jvmopts
                "", //      String javaPath,
                "",  //      String prefixStartSlaveCmd,
                "", //      String suffixStartSlaveCmd,
                20, //      Integer launchTimeoutSeconds,
                1, //      Integer maxNumRetries,
                3,//      Integer retryWaitTime
                new NonVerifyingKeyVerificationStrategy()
        );
        final DumbSlave dumbSlave = new DumbSlave("docker-daemon", "/home/vagrant/jenkins2", sshLauncher);
        jRule.getInstance().addNode(dumbSlave);
        await().timeout(60, SECONDS).until(() -> assertThat(dumbSlave.getChannel(), notNullValue()));
//        String dockerfilePath = dumbSlave.getChannel().call(new DockerBuildImageStepTest.StringThrowableCallable());


        final CredentialsYADockerConnector dockerConnector = new CredentialsYADockerConnector()
                .withConnectorType(JERSEY)
                .withServerUrl("tcp://127.0.0.1:2376")
                .withSslConfig(new LocalDirectorySSLConfig("/home/vagrant/keys"));
//                .withCredentials(new DockerDaemonFileCredentials(null, "docker-cert", "",
//                        "/home/vagrant/keys"));

        DockerShellStep dockerShellStep = new DockerShellStep();
        dockerShellStep.setShellScript("env && pwd");
        dockerShellStep.setConnector(dockerConnector);

        FreeStyleProject project = jRule.createFreeStyleProject("test");
        project.getBuildersList().add(dockerShellStep);

        project.save();

        QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);
        FreeStyleBuild freeStyleBuild = taskFuture.get();

        jRule.waitForCompletion(freeStyleBuild);

        jRule.assertBuildStatusSuccess(freeStyleBuild);
    }
 
Example 16
Source File: GitHubBranchTriggerITest.java    From github-integration-plugin with MIT License 3 votes vote down vote up
@Test
public void freestyleTest() throws Exception {
    // create job
    FreeStyleProject job = jRule.createFreeStyleProject("freestyle-job");

    job.addProperty(getPreconfiguredProperty(ghRule.getGhRepo()));

    job.addTrigger(getDefaultBranchTrigger());

    job.getBuildersList().add(new Shell("env && sleep 2"));

    job.save();

    super.smokeTest(job);
}
 
Example 17
Source File: GogsWebHookJenkinsTest.java    From gogs-webhook-plugin with MIT License 3 votes vote down vote up
private FreeStyleProject prepareProjectWithGogsProperty(Secret secret) throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();

    GogsProjectProperty prop = new GogsProjectProperty(secret, true, "master");
    p.addProperty(prop);

    p.save();

    return p;
}