public PollingResult pollSCMChanges(FreeStyleProject p) { return p.poll(new StreamTaskListener(System.out, Charset .defaultCharset())); }
/** * Test that multiple repository URLs are all polled. */ @Issue("JENKINS-3168") @Test public void pollMultipleRepositories() throws Exception { // fetch the current workspaces FreeStyleProject p = r.createFreeStyleProject(); String svnBase = "file://" + new CopyExisting(getClass().getResource("/svn-repo.zip")).allocate().toURI().toURL().getPath(); SubversionSCM scm = new SubversionSCM( Arrays.asList(new ModuleLocation(svnBase + "trunk", null), new ModuleLocation(svnBase + "branches", null)), new CheckoutUpdater(), null, null, null, null, null, null); p.setScm(scm); p.scheduleBuild2(0, new Cause.UserIdCause()).get(); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); assertFalse(p.poll(listener).hasChanges()); createCommit(scm,"branches/foo"); assertTrue("any change in any of the repository should be detected",p.poll(listener).hasChanges()); assertFalse("no change since the last polling",p.poll(listener).hasChanges()); createCommit(scm,"trunk/foo"); assertTrue("another change in the repo should be detected separately",p.poll(listener).hasChanges()); }
@Issue("JENKINS-16533") @Test public void pollingRespectExternalsWithRevision() throws Exception { // trunk has svn:externals="-r 1 ^/vendor vendor" (pinned) // latest commit on vendor is r3 (> r1) File repo = new CopyExisting(getClass().getResource("JENKINS-16533.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath() + "trunk"); // pinned externals should be recorded with ::p in revisions.txt FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // should not find any change (pinned externals should be skipped on poll) // fail if it checks the revision of external URL larger than the pinned revision assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges()); }
/** * Do the polling on the slave and make sure it works. */ @Issue("JENKINS-4299") @Test public void polling() throws Exception { // SLAVE_DEBUG_PORT = 8001; File repo = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath()); FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // initial polling on the slave for the code path that doesn't find any change assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges()); createCommit(scm, "foo"); // polling on the slave for the code path that doesn't find any change assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges()); }
/** * Used for experimenting the memory leak problem. * This test by itself doesn't detect that, but I'm leaving it in anyway. */ @Issue("JENKINS-8061") @Test public void pollingLeak() throws Exception { Proc p = runSvnServe(getClass().getResource("small.zip")); try { FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/")); b.setAssignedNode(r.createSlave()); r.assertBuildStatusSuccess(b.scheduleBuild2(0)); b.poll(new StreamTaskListener(System.out,Charset.defaultCharset())); } finally { p.kill(); } }
private void invokeTestPollingExternalsForFile() throws Exception { // trunk has svn:externals="^/vendor/target.txt target.txt" File repo = new CopyExisting(getClass().getResource("JENKINS-20165.zip")).allocate(); String path = "file://" + repo.toURI().toURL().getPath(); SubversionSCM scm = new SubversionSCM(path + "trunk"); // first checkout FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); // update target.txt in vendor SubversionSCM vendor = new SubversionSCM(path + "vendor"); createWorkingCopy(vendor); changeFiles("target.txt"); commitWorkingCopy("update"); // should detect change assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges()); } }
/** * {@link SubversionSCM#pollChanges(AbstractProject , Launcher , FilePath, TaskListener)} should notice * if the workspace and the current configuration is inconsistent and schedule a new build. */ @Email("http://www.nabble.com/Proper-way-to-switch---relocate-SVN-tree---tt21173306.html") @Test public void pollingAfterRelocation() throws Exception { // fetch the current workspace FreeStyleProject p = r.createFreeStyleProject(); p.setScm(loadSvnRepo()); p.scheduleBuild2(0, new Cause.UserIdCause()).get(); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); assertFalse(p.poll(listener).hasChanges()); // now switch the repository to a new one. // this time the polling should indicate that we need a new build p.setScm(loadSvnRepo()); assertTrue(p.poll(listener).hasChanges()); // build it once again to switch p.scheduleBuild2(0, new Cause.UserIdCause()).get(); // then no more change should be detected assertFalse(p.poll(listener).hasChanges()); }
@Test public void masterPolling() throws Exception { File repo = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath()); scm.setPollFromMaster(true); FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); p.setAssignedLabel(r.createSlave().getSelfLabel()); r.assertBuildStatusSuccess(p.scheduleBuild2(2).get()); // initial polling on the master for the code path that doesn't find any change assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges()); // create a commit FreeStyleProject forCommit = r.createFreeStyleProject(); forCommit.setScm(scm); forCommit.setAssignedLabel(r.jenkins.getSelfLabel()); FreeStyleBuild b = r.assertBuildStatusSuccess(forCommit.scheduleBuild2(0).get()); FilePath newFile = b.getWorkspace().child("foo"); newFile.touch(System.currentTimeMillis()); SvnClientManager svnm = SubversionSCM.createClientManager(p); svnm.getWCClient().doAdd(new File(newFile.getRemote()),false,false,false, SVNDepth.INFINITY, false,false); SVNCommitClient cc = svnm.getCommitClient(); cc.doCommit(new File[]{new File(newFile.getRemote())},false,"added",null,null,false,false,SVNDepth.INFINITY); // polling on the master for the code path that doesn't find any change assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges()); }
@Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void excludeByUser() throws Exception { FreeStyleProject p = r.createFreeStyleProject( "testExcludeByUser" ); p.setScm(new SubversionSCM( Arrays.asList( new ModuleLocation( "https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusions@19438", null )), new UpdateUpdater(), null, "", "dty", "", "", null) ); // Do a build to force the creation of the workspace. This works around // pollChanges returning true when the workspace does not exist. p.scheduleBuild2(0).get(); boolean foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertFalse("Polling found changes that should have been ignored", foundChanges); }
commitWorkingCopy("meta only"); boolean foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertFalse("Property only changes commit should have been ignored.", foundChanges); commitWorkingCopy("meta + add"); foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertTrue("Non Property only changes (adds) commit should not be ignored.", foundChanges); commitWorkingCopy("meta + files"); foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertTrue("Non Property only changes (modify) commit should not be ignored.", foundChanges); commitWorkingCopy("files"); foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertTrue("Non Property only changes commit should not be ignored.", foundChanges); commitWorkingCopy("meta only"); foundChanges = p.poll(r.createTaskListener()).hasChanges(); assertFalse("Property only changes commit should be ignored.", foundChanges);
/** * Check out a pinned external and the same url unpinned. * See that we can poll afterward w/o getting confused. */ @Issue("JENKINS-6209") @Test public void pinnedExternals() throws Exception { Proc p = runSvnServe(getClass().getResource("JENKINS-6209.zip")); try { FreeStyleProject b = r.createFreeStyleProject(); ModuleLocation[] locations = { new ModuleLocation("svn://localhost/y", null), new ModuleLocation("svn://localhost/z", null) }; b.setScm(new SubversionSCM(Arrays.asList(locations), new CheckoutUpdater(), null, null, null, null, null, null)); FreeStyleBuild build = r.assertBuildStatusSuccess(b.scheduleBuild2(0)); FilePath ws = build.getWorkspace(); assertEquals(ws.child("z").child("a").readToString(),"za 2\n"); assertEquals(ws.child("y").child("z").child("a").readToString(),"za 1\n"); assertEquals(b.poll(StreamTaskListener.fromStdout()).change, PollingResult.Change.NONE); } finally { p.kill(); } }
/** * This test aims to verify that the environment variables (from Global Properties section) are available in SCM * Polling. */ @Ignore("TODO org.tmatesoft.svn.core.SVNException: svn: E175002: PROPFIND of '/trunk/jenkins/test-projects/model-maven-project': 405 Method Not Allowed (https://svn.jenkins-ci.org)") @Issue("JENKINS-31067") @Test public void pollingWithEnvVars() throws Exception { jenkins.getInstance().getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("BRANCH", "trunk"))); FreeStyleProject project = jenkins.createFreeStyleProject(); project.setScm(new SubversionSCM(REPO_URL)); jenkins.assertBuildStatusSuccess(project.scheduleBuild2(0).get()); TaskListener listener = jenkins.createTaskListener(); PollingResult poll = project.poll(listener); assertFalse(poll.hasChanges()); } }
/** * This test aims to verify that the variables defined in the "Properties Content" field, are availables in SCM Polling. */ @Ignore("TODO org.tmatesoft.svn.core.SVNException: svn: E175002: PROPFIND of '/trunk/hudson/test-projects/trivial-maven': 405 Method Not Allowed (https://svn.jenkins-ci.org)") @Issue("JENKINS-29340") @Test public void pollingWithEnvInject() throws Exception { FreeStyleProject project = jenkins.createFreeStyleProject(); EnvInjectJobPropertyInfo jobPropertyInfo = new EnvInjectJobPropertyInfo(null, "REPO=trivial-maven", null, null, null, false); EnvInjectJobProperty envInjectJobProperty = new EnvInjectJobProperty(); envInjectJobProperty.setOn(true); envInjectJobProperty.setInfo(jobPropertyInfo); project.addProperty(envInjectJobProperty); project.setScm(new SubversionSCM(REPO_URL)); TaskListener listener = jenkins.createTaskListener(); PollingResult poll = project.poll(listener); // If true means that parameters have been replaced correctly and we have a valid repository URL. assertTrue(poll.hasChanges()); jenkins.assertBuildStatusSuccess(project.scheduleBuild2(0).get()); } }
@Issue("JENKINS-22568") @Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void pollingWithChoiceParametersWithOutCurlyBraces() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); String repo = "https://svn.jenkins-ci.org/"; String path = "trunk/hudson/test-projects/trivial-maven/src/test/java/test"; p.setScm(new SubversionSCM("${REPO}" + path)); ParametersDefinitionProperty property = new ParametersDefinitionProperty(new ChoiceParameterDefinition("REPO", new String[] {repo, "test"}, "")); p.addProperty(property); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("REPO", repo))).get(); r.assertBuildStatus(Result.SUCCESS,b); assertTrue(b.getWorkspace().child("AppTest.java").exists()); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); PollingResult poll = p.poll(listener); assertFalse("Polling shouldn't have any changes.", poll.hasChanges()); }
@Issue("JENKINS-22568") @Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void pollingWithDefaultParametersWithCurlyBraces() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); String repo = "https://svn.jenkins-ci.org/"; String path = "trunk/hudson/test-projects/trivial-ant/"; p.setScm(new SubversionSCM("${REPO}" + path)); ParametersDefinitionProperty property = new ParametersDefinitionProperty(new StringParameterDefinition("REPO", repo)); p.addProperty(property); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("REPO", repo))).get(); r.assertBuildStatus(Result.SUCCESS,b); assertTrue(b.getWorkspace().child("build.xml").exists()); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); PollingResult poll = p.poll(listener); assertFalse("Polling shouldn't have any changes.", poll.hasChanges()); }
@Issue("JENKINS-22568") @Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void pollingWithDefaultParametersWithOutCurlyBraces() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); String repo = "https://svn.jenkins-ci.org"; String path = "/trunk/hudson/test-projects/trivial-ant/"; p.setScm(new SubversionSCM("$REPO" + path)); ParametersDefinitionProperty property = new ParametersDefinitionProperty(new StringParameterDefinition("REPO", repo)); p.addProperty(property); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause(), new ParametersAction(new StringParameterValue("REPO", repo))).get(); r.assertBuildStatus(Result.SUCCESS,b); assertTrue(b.getWorkspace().child("build.xml").exists()); // as a baseline, this shouldn't detect any change TaskListener listener = r.createTaskListener(); PollingResult poll = p.poll(listener); assertFalse("Polling shouldn't have any changes.", poll.hasChanges()); }