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;
}
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());
}
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);
}
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();
}
Aggregations