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

The following examples show how to use hudson.model.FreeStyleProject#setQuietPeriod() . 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: PushHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void push_ciSkip() throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    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()
            .withCommits(Arrays.asList(commit().withMessage("some message").build(),
                                       commit().withMessage("[ci-skip]").build()))
            .build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example 2
Source File: PipelineHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
/**
 * always triggers since pipeline events do not contain ci skip message
 */
public void pipeline_ciSkip() throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    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);
    pipelineHookTriggerHandler.handle(project, pipelineHook , true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
        newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example 3
Source File: PipelineHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void pipeline_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {

    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    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);

    pipelineHookTriggerHandler.handle(project, pipelineHook, false, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example 4
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
private boolean ciSkipTestHelper(String MRDescription, String lastCommitMsg) throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    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 mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.reopened), Arrays.asList(Action.approved), false, false, false);
    mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
            .withObjectAttributes(defaultMergeRequestObjectAttributes().withDescription(MRDescription).withLastCommit(commit().withMessage(lastCommitMsg).withAuthor(user().withName("test").build()).withId("testid").build()).build())
            .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
        newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    return buildTriggered.isSignaled();
}
 
Example 5
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 6
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 7
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 8
Source File: PendingBuildsHandlerTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private Project freestyleProject(String name, GitLabCommitStatusPublisher gitLabCommitStatusPublisher) throws IOException {
    FreeStyleProject project = jenkins.createFreeStyleProject(name);
    project.setQuietPeriod(5000);
    project.getPublishersList().add(gitLabCommitStatusPublisher);
    project.addProperty(gitLabConnectionProperty);
    return project;
}
 
Example 9
Source File: NoteHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void note_ciSkip() throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    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().withDescription("[ci-skip]").build())
            .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example 10
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 11
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 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_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 13
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));
}