Search in sources :

Example 1 with SCMTrigger

use of hudson.triggers.SCMTrigger in project hudson-2.x by hudson.

the class AbstractProject method schedulePolling.

/**
 * Schedules a polling of this project.
 */
public boolean schedulePolling() {
    if (isDisabled())
        return false;
    SCMTrigger scmt = getTrigger(SCMTrigger.class);
    if (scmt == null)
        return false;
    scmt.run();
    return true;
}
Also used : SCMTrigger(hudson.triggers.SCMTrigger)

Example 2 with SCMTrigger

use of hudson.triggers.SCMTrigger in project workflow-cps-plugin by jenkinsci.

the class CpsScmFlowDefinitionTest method changelogAndPolling.

@Test
public void changelogAndPolling() throws Exception {
    sampleRepo.init();
    sampleRepo.write("flow.groovy", "echo 'version one'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=init");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    // no schedule, use notifyCommit only
    p.addTrigger(new SCMTrigger(""));
    CpsScmFlowDefinition def = new CpsScmFlowDefinition(new GitStep(sampleRepo.toString()).createSCM(), "flow.groovy");
    def.setLightweight(false);
    p.setDefinition(def);
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    r.assertLogContains("Cloning the remote Git repository", b);
    r.assertLogContains("version one", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    sampleRepo.write("flow.groovy", "echo 'version two'");
    sampleRepo.git("add", "flow.groovy");
    sampleRepo.git("commit", "--message=next");
    sampleRepo.notifyCommit(r);
    b = p.getLastBuild();
    assertEquals(2, b.number);
    r.assertLogContains("Fetching changes from the remote Git repository", b);
    r.assertLogContains("version two", b);
    r.assertLogNotContains("Retrying after 10 seconds", b);
    List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
    assertEquals(1, changeSets.size());
    ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0);
    assertEquals(b, changeSet.getRun());
    assertEquals("git", changeSet.getKind());
    Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator();
    assertTrue(iterator.hasNext());
    ChangeLogSet.Entry entry = iterator.next();
    assertEquals("[flow.groovy]", entry.getAffectedPaths().toString());
    assertFalse(iterator.hasNext());
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) SCMTrigger(hudson.triggers.SCMTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) GitStep(jenkins.plugins.git.GitStep) Test(org.junit.Test)

Example 3 with SCMTrigger

use of hudson.triggers.SCMTrigger in project workflow-job-plugin by jenkinsci.

the class WorkflowJobTest method polling.

@Issue("JENKINS-34716")
@Test
public void polling() throws Exception {
    sampleRepo.init();
    sampleRepo.write("Jenkinsfile", "echo 'first version'");
    sampleRepo.git("add", "Jenkinsfile");
    sampleRepo.git("commit", "-m", "init");
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
    p.addTrigger(new SCMTrigger(""));
    p.setDefinition(new CpsScmFlowDefinition(new GitSCM(sampleRepo.toString()), "Jenkinsfile"));
    j.assertLogContains("first version", j.buildAndAssertSuccess(p));
    sampleRepo.write("Jenkinsfile", "echo 'second version'");
    sampleRepo.git("commit", "-a", "-m", "init");
    j.jenkins.setQuietPeriod(0);
    j.createWebClient().getPage(new WebRequest(j.createWebClient().createCrumbedUrl(p.getUrl() + "polling"), HttpMethod.POST));
    j.waitUntilNoActivity();
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(2, b2.getNumber());
    j.assertLogContains("second version", b2);
}
Also used : SCMTrigger(hudson.triggers.SCMTrigger) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) CpsScmFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition) GitSCM(hudson.plugins.git.GitSCM) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 4 with SCMTrigger

use of hudson.triggers.SCMTrigger in project hudson-2.x by hudson.

the class LegacyProjectTest method testConvertLegacyTriggers.

/**
 * Tests unmarshalling FreeStyleProject configuration and checks whether Triggers properties
 * from Job are configured.
 *
 * @throws Exception if any.
 */
@Test
public void testConvertLegacyTriggers() throws Exception {
    AbstractProject project = (AbstractProject) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    Hudson hudson = createMock(Hudson.class);
    String scmTriggerPropertyKey = "hudson-trigger-SCMTrigger";
    TriggerDescriptor scmTriggerDescriptor = createMock(SCMTrigger.DescriptorImpl.class);
    expect(scmTriggerDescriptor.getJsonSafeClassName()).andReturn(scmTriggerPropertyKey);
    expect(hudson.getDescriptorOrDie(SCMTrigger.class)).andReturn(scmTriggerDescriptor);
    String timerTriggerPropertyKey = "hudson-trigger-TimerTrigger";
    TriggerDescriptor timerTriggerDescriptor = createMock(TimerTrigger.DescriptorImpl.class);
    expect(timerTriggerDescriptor.getJsonSafeClassName()).andReturn(timerTriggerPropertyKey);
    expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(timerTriggerDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    project.setAllowSave(false);
    project.initProjectProperties();
    assertNull(project.getProperty(scmTriggerPropertyKey));
    assertNull(project.getProperty(timerTriggerPropertyKey));
    project.convertTriggerProperties();
    assertNotNull(project.getProperty(scmTriggerPropertyKey));
    Trigger trigger = (Trigger) project.getProperty(scmTriggerPropertyKey).getValue();
    assertEquals("5 * * * *", trigger.getSpec());
    assertNotNull(project.getProperty(timerTriggerPropertyKey));
    trigger = (Trigger) project.getProperty(timerTriggerPropertyKey).getValue();
    assertEquals("*/10 * * * *", trigger.getSpec());
    verifyAll();
}
Also used : Trigger(hudson.triggers.Trigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) TriggerDescriptor(hudson.triggers.TriggerDescriptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SCMTrigger (hudson.triggers.SCMTrigger)4 Test (org.junit.Test)3 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 GitSCM (hudson.plugins.git.GitSCM)1 ChangeLogSet (hudson.scm.ChangeLogSet)1 TimerTrigger (hudson.triggers.TimerTrigger)1 Trigger (hudson.triggers.Trigger)1 TriggerDescriptor (hudson.triggers.TriggerDescriptor)1 GitStep (jenkins.plugins.git.GitStep)1 CpsScmFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 Issue (org.jvnet.hudson.test.Issue)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1