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

The following examples show how to use hudson.model.FreeStyleProject#setScm() . 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 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 2
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 3
Source File: AbstractGitTestCase.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
protected FreeStyleProject setupProject(List<BranchSpec> branches, boolean authorOrCommitter,
    String relativeTargetDir, String excludedRegions,
    String excludedUsers, String localBranch, boolean fastRemotePoll,
    String includedRegions, List<SparseCheckoutPath> sparseCheckoutPaths) throws Exception {
  FreeStyleProject project = createFreeStyleProject();
  GitSCM scm = new GitSCM(
      createRemoteRepositories(),
      branches,
      false, Collections.<SubmoduleConfig>emptyList(),
      null, null,
      Collections.<GitSCMExtension>emptyList());
  scm.getExtensions().add(new DisableRemotePoll()); // don't work on a file:// repository
  if (relativeTargetDir!=null)
    scm.getExtensions().add(new RelativeTargetDirectory(relativeTargetDir));
  if (excludedUsers!=null)
    scm.getExtensions().add(new UserExclusion(excludedUsers));
  if (excludedRegions!=null || includedRegions!=null)
    scm.getExtensions().add(new PathRestriction(includedRegions,excludedRegions));

  scm.getExtensions().add(new SparseCheckoutPaths(sparseCheckoutPaths));

  project.setScm(scm);
  project.getBuildersList().add(new CaptureEnvironmentBuilder());
  return project;
}
 
Example 4
Source File: AbstractFreestyleTestProject.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
protected void subscribeProject(final ProjectFixture fixture) throws Exception {
        String name = UUID.randomUUID().toString();

        final FreeStyleProject job = jenkinsRule.getInstance().createProject(FreeStyleProject.class, name);
        job.setScm(new NullSCM());
        if (fixture.getScm() != null) {
            job.setScm(fixture.getScm());
        }

        final String uuid = this.sqsQueue.getUuid();

        SQSTrigger trigger = null;

        if (fixture.isHasTrigger()) {
            trigger = new SQSTrigger(uuid, fixture.isSubscribeInternalScm(), fixture.getScmConfigs());
        }

//        final OneShotEvent event = new OneShotEvent();
        fixture.setEvent(new OneShotEvent());
        job.getBuildersList().add(new TestBuilder() {

            @Override
            public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
                fixture.setLastBuild(job.getLastBuild());
                fixture.getEvent().signal();
                return true;
            }
        });
        job.setQuietPeriod(0);

        if (trigger != null) {
            trigger.start(job, false);
            job.addTrigger(trigger);
        }

//        fixture.setEvent(event);
    }
 
Example 5
Source File: BuildStatusActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void successfulBuild() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.setScm(new GitSCM(gitRepoUrl));
    FreeStyleBuild build = testProject.scheduleBuild2(0).get();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mockResponse(out);
    getBuildStatusAction(testProject).execute(response);

    assertSuccessfulBuild(build, out, response);
}
 
Example 6
Source File: BuildStatusActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void notFoundBuild() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.setScm(new GitSCM(gitRepoUrl));


    ByteArrayOutputStream out = new ByteArrayOutputStream();
    mockResponse(out);
    getBuildStatusAction(testProject).execute(response);

    assertNotFoundBuild(out, response);
}
 
Example 7
Source File: BuildPageRedirectActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void redirectToBuildUrl() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.setScm(new GitSCM(gitRepoUrl));
    testProject.setQuietPeriod(0);
    QueueTaskFuture<FreeStyleBuild> future = testProject.scheduleBuild2(0);
    FreeStyleBuild build = future.get(15, TimeUnit.SECONDS);

    getBuildPageRedirectAction(testProject).execute(response);

    verify(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getUrl());
}
 
Example 8
Source File: BuildPageRedirectActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void redirectToBuildStatusUrl() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.setScm(new GitSCM(gitRepoUrl));
    testProject.setQuietPeriod(0);
    QueueTaskFuture<FreeStyleBuild> future = testProject.scheduleBuild2(0);
    FreeStyleBuild build = future.get(15, TimeUnit.SECONDS);

    doThrow(IOException.class).when(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getUrl());
    getBuildPageRedirectAction(testProject).execute(response);

    verify(response).sendRedirect2(jenkins.getInstance().getRootUrl() + build.getBuildStatusUrl());
}
 
Example 9
Source File: NoteBuildActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void build_alreadyBuiltMR_alreadyBuiltMR() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.addTrigger(trigger);
    testProject.setScm(new GitSCM(gitRepoUrl));
    QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new ParametersAction(new StringParameterValue("gitlabTargetBranch", "master")));
    future.get();

    exception.expect(HttpResponses.HttpResponseException.class);
    new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);

    verify(trigger).onPost(any(NoteHook.class));
}
 
Example 10
Source File: NoteBuildActionTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void build_alreadyBuiltMR_differentTargetBranch() throws IOException, ExecutionException, InterruptedException {
    FreeStyleProject testProject = jenkins.createFreeStyleProject();
    testProject.addTrigger(trigger);
    testProject.setScm(new GitSCM(gitRepoUrl));
    QueueTaskFuture<?> future = testProject.scheduleBuild2(0, new GitLabWebHookCause(causeData()
            .withActionType(CauseData.ActionType.NOTE)
            .withSourceProjectId(1)
            .withTargetProjectId(1)
            .withBranch("feature")
            .withSourceBranch("feature")
            .withUserName("")
            .withSourceRepoHomepage("https://gitlab.org/test")
            .withSourceRepoName("test")
            .withSourceNamespace("test-namespace")
            .withSourceRepoUrl("[email protected]:test.git")
            .withSourceRepoSshUrl("[email protected]:test.git")
            .withSourceRepoHttpUrl("https://gitlab.org/test.git")
            .withMergeRequestTitle("Test")
            .withMergeRequestId(1)
            .withMergeRequestIid(1)
            .withTargetBranch("master")
            .withTargetRepoName("test")
            .withTargetNamespace("test-namespace")
            .withTargetRepoSshUrl("[email protected]:test.git")
            .withTargetRepoHttpUrl("https://gitlab.org/test.git")
            .withTriggeredByUser("test")
            .withLastCommit("123")
            .withTargetProjectUrl("https://gitlab.org/test")
            .build()));
    future.get();

    exception.expect(HttpResponses.HttpResponseException.class);
    new NoteBuildAction(testProject, getJson("NoteEvent_alreadyBuiltMR.json"), null).execute(response);

    verify(trigger).onPost(any(NoteHook.class));
}
 
Example 11
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler,
		MergeRequestObjectAttributesBuilder objectAttributes) throws GitAPIException, IOException,
           InterruptedException {
	Git.init().setDirectory(tmp.getRoot()).call();
       tmp.newFile("test");
       Git git = Git.open(tmp.getRoot());
       git.add().addFilepattern("test");
       RevCommit commit = git.commit().setMessage("test").call();
       ObjectId head = git.getRepository().resolve(Constants.HEAD);
       String repositoryUrl = tmp.getRoot().toURI().toString();

       final OneShotEvent buildTriggered = new OneShotEvent();
       FreeStyleProject project = jenkins.createFreeStyleProject();
       project.setScm(new GitSCM(repositoryUrl));
       project.getBuildersList().add(new TestBuilder() {
           @Override
           public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
               buildTriggered.signal();
               return true;
           }
       });
       project.setQuietPeriod(0);
	mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
               .withObjectAttributes(objectAttributes
           		    .withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
           		    .withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
                   .build())
               .withProject(project()
                   .withWebUrl("https://gitlab.org/test.git")
                   .build()
               )
               .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
           newMergeRequestLabelFilter(null));

       buildTriggered.block(10000);
       return buildTriggered;
}
 
Example 12
Source File: PushHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void push_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    Git.init().setDirectory(tmp.getRoot()).call();
    tmp.newFile("test");
    Git git = Git.open(tmp.getRoot());
    git.add().addFilepattern("test");
    RevCommit commit = git.commit().setMessage("test").call();
    ObjectId head = git.getRepository().resolve(Constants.HEAD);
    String repositoryUrl = tmp.getRoot().toURI().toString();

    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.setScm(new GitSCM(repositoryUrl));
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    project.setQuietPeriod(0);
    pushHookTriggerHandler.handle(project, pushHook()
            .withBefore("0000000000000000000000000000000000000000")
            .withProjectId(1)
            .withUserName("test")
            .withObjectKind("tag_push")
            .withRepository(repository()
                    .withName("test")
                    .withHomepage("https://gitlab.org/test")
                    .withUrl("[email protected]:test.git")
                    .withGitSshUrl("[email protected]:test.git")
                    .withGitHttpUrl("https://gitlab.org/test.git")
                    .build())
            .withProject(project()
                    .withNamespace("test-namespace")
                    .withWebUrl("https://gitlab.org/test")
                    .build())
            .withAfter(commit.name())
            .withRef("refs/heads/" + git.nameRev().add(head).call().get(head))
            .build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example 13
Source File: PushHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void push_build2DifferentBranchesButSameCommit() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    Git.init().setDirectory(tmp.getRoot()).call();
    tmp.newFile("test");
    Git git = Git.open(tmp.getRoot());
    git.add().addFilepattern("test");
    RevCommit commit = git.commit().setMessage("test").call();
    ObjectId head = git.getRepository().resolve(Constants.HEAD);
    String repositoryUrl = tmp.getRoot().toURI().toString();

    final AtomicInteger buildCount = new AtomicInteger(0);

    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.setScm(new GitSCM(repositoryUrl));
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            int count = buildCount.incrementAndGet();
            if (count == 2) {
                buildTriggered.signal();
            }
            return true;
        }
    });
    project.setQuietPeriod(0);
    PushHookBuilder pushHookBuilder = pushHook()
        .withBefore("0000000000000000000000000000000000000000")
        .withProjectId(1)
        .withUserName("test")
        .withObjectKind("push")
        .withRepository(repository()
                            .withName("test")
                            .withHomepage("https://gitlab.org/test")
                            .withUrl("[email protected]:test.git")
                            .withGitSshUrl("[email protected]:test.git")
                            .withGitHttpUrl("https://gitlab.org/test.git")
                            .build())
        .withProject(project()
                         .withNamespace("test-namespace")
                         .withWebUrl("https://gitlab.org/test")
                         .build())
        .withAfter(commit.name())
        .withRef("refs/heads/" + git.nameRev().add(head).call().get(head));
    pushHookTriggerHandler.handle(project, pushHookBuilder.build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));
    pushHookTriggerHandler.handle(project, pushHookBuilder
                                      .but().withRef("refs/heads/" + git.nameRev().add(head).call().get(head) + "-2").build(), true,
                                  newBranchFilter(branchFilterConfig().build(BranchFilterType.All)), newMergeRequestLabelFilter(null));
    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
    assertThat(buildCount.intValue(), is(2));
}
 
Example 14
Source File: NoteHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void note_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    Git.init().setDirectory(tmp.getRoot()).call();
    tmp.newFile("test");
    Git git = Git.open(tmp.getRoot());
    git.add().addFilepattern("test");
    RevCommit commit = git.commit().setMessage("test").call();
    ObjectId head = git.getRepository().resolve(Constants.HEAD);
    String repositoryUrl = tmp.getRoot().toURI().toString();

    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.setScm(new GitSCM(repositoryUrl));
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    Date currentDate = new Date();
    project.setQuietPeriod(0);
    noteHookTriggerHandler.handle(project, noteHook()
            .withObjectAttributes(noteObjectAttributes()
                .withId(1)
                .withNote("ci-run")
                .withAuthorId(1)
                .withProjectId(1)
                .withCreatedAt(currentDate)
                .withUpdatedAt(currentDate)
                .withUrl("https://gitlab.org/test/merge_requests/1#note_1")
                .build())
            .withMergeRequest(mergeRequestObjectAttributes()
                .withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
                .withState(State.opened)
                .withIid(1)
                .withTitle("test")
                .withTargetProjectId(1)
                .withSourceProjectId(1)
                .withSourceBranch("feature")
                .withTargetBranch("master")
                .withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
                .withSource(project()
                    .withName("test")
                    .withNamespace("test-namespace")
                    .withHomepage("https://gitlab.org/test")
                    .withUrl("[email protected]:test.git")
                    .withSshUrl("[email protected]:test.git")
                    .withHttpUrl("https://gitlab.org/test.git")
                    .build())
                .withTarget(project()
                    .withName("test")
                    .withNamespace("test-namespace")
                    .withHomepage("https://gitlab.org/test")
                    .withUrl("[email protected]:test.git")
                    .withSshUrl("[email protected]:test.git")
                    .withHttpUrl("https://gitlab.org/test.git")
                    .withWebUrl("https://gitlab.org/test.git")
                    .build())
                .build())
            .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}