return 0; if (!item.poll(new StreamTaskListener(stdout, getClientCharset())).hasChanges()) return 0; throw new IllegalStateException(BUILD_SCHEDULING_REFUSED); Run<?,?> b = f.waitForStart(); // wait for the start stdout.println("Started "+b.getFullDisplayName()); stdout.flush(); f.get(); // wait for the completion stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult()); return b.getResult().ordinal; } else { f.cancel(true); Exception myException = new AbortException(); myException.initCause(e);
@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()); }
@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()); }
/** * {@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()); }
m.hg(repo, "branch", "b"); m.touchAndCommit(repo, "b-1"); FreeStyleProject p = j.createFreeStyleProject(); p.setScm(new MercurialSCM(inst != null ? inst.getName() : null, repo.getRemote(), "b", null, null, null, false)); m.buildAndCheck(p, "b-1"); m.hg(repo, "update", "--clean", "default"); m.touchAndCommit(repo, "default-2"); assertFalse(m.pollSCMChanges(p).hasChanges()); m.hg(repo, "update", "--clean", "b"); m.touchAndCommit(repo, "b-2"); assertTrue(m.pollSCMChanges(p).hasChanges()); m.buildAndCheck(p, "b-2"); p.setScm(new MercurialSCM(inst != null ? inst.getName() : null, repo.getRemote(), null, null, null, null, false)); assertTrue(m.pollSCMChanges(p).hasChanges()); assertFalse(m.pollSCMChanges(p).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()); }
@Bug(12162) @Test public void changelogInMultiSCM() throws Exception { FreeStyleProject p = j.createFreeStyleProject(); m.hg(repo, "init"); m.touchAndCommit(repo, "r1f1"); File repo2 = tmp.newFolder(); m.hg(repo2, "init"); m.touchAndCommit(repo2, "r2f1"); p.setScm(new MultiSCM(Arrays.<SCM>asList( new MercurialSCM(hgInstallation(), repo.getPath(), null, null, "r1", null, false), new MercurialSCM(hgInstallation(), repo2.getPath(), null, null, "r2", null, false)))); FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); m.touchAndCommit(repo, "r1f2"); m.touchAndCommit(repo2, "r2f2"); assertTrue(m.pollSCMChanges(p).hasChanges()); b = j.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); List<Set<String>> paths = new ArrayList<Set<String>>(); // TODO "r1/r1f2" etc. would be preferable; probably requires determineChanges to prepend subdir? paths.add(Collections.singleton("r1f2")); paths.add(Collections.singleton("r2f2")); assertChangeSetPaths(paths, b); }
/** * Checks if there's any update in SCM, and returns true if any is found. * * @deprecated as of 1.346 * Use {@link #poll(TaskListener)} instead. */ @Deprecated public boolean pollSCMChanges( TaskListener listener ) { return poll(listener).hasChanges(); }
protected PollingResult compareRemoteRevisionInternal(EnvVars env, Launcher launcher, TaskListener listener, SCMRevisionState baseline) { listener.getLogger().println( String.format(MessageConstants.SCM_COMP, DISPLAY_NAME, getImageStreamName(env), tag, getNamespace(env))); String commitId = this.getCommitId(listener, env); ImageStreamRevisionState currIMSState = null; if (commitId != null) currIMSState = new ImageStreamRevisionState(commitId); boolean chatty = Boolean.parseBoolean(verbose); if (chatty) listener.getLogger().println( "\n\nOpenShiftImageStreams compareRemoteRevisionWith comparing baseline " + baseline + " with lastest " + currIMSState); boolean changes = false; if (baseline != null && baseline instanceof ImageStreamRevisionState && currIMSState != null) changes = !currIMSState.equals(baseline); if (baseline == null && currIMSState != null) { changes = true; } if (changes) { lastCommitId = commitId; listener.getLogger().println(MessageConstants.SCM_CHANGE); } else { listener.getLogger().println(MessageConstants.SCM_NO_CHANGE); } return new PollingResult(baseline, currIMSState, changes ? Change.SIGNIFICANT : Change.NONE); }
@Test public void multipleProjectsForSingleSource() throws Exception { FreeStyleProject one = j.createFreeStyleProject(); FreeStyleProject two = j.createFreeStyleProject(); FreeStyleProject three = j.createFreeStyleProject(); FreeStyleProject four = j.createFreeStyleProject(); one.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), null, null, null, null, false)); two.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), null, null, null, null, false)); three.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), "b", null, null, null, false)); four.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), "b", null, null, null, false)); m.hg(repo, "init"); m.touchAndCommit(repo, "f1"); assertTrue(m.pollSCMChanges(one).hasChanges()); m.buildAndCheck(one, "f1"); assertTrue(m.pollSCMChanges(two).hasChanges()); m.hg(repo, "branch", "b"); m.touchAndCommit(repo, "b1"); assertFalse(m.pollSCMChanges(one).hasChanges()); m.buildAndCheck(three, "b1"); m.buildAndCheck(four, "b1"); m.touchAndCommit(repo, "b2"); assertTrue(m.pollSCMChanges(three).hasChanges()); m.buildAndCheck(three, "b2"); assertTrue(m.pollSCMChanges(four).hasChanges()); assertFalse(m.pollSCMChanges(one).hasChanges()); }
@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()); }
new UpdateUpdater(), null, "", "", "", "", ".*/foo"); FreeStyleProject p = r.createFreeStyleProject("testExcludedRegions"); p.setScm(scm); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); assertFalse(p.poll(r.createTaskListener()).hasChanges()); p.poll(r.createTaskListener()).hasChanges()); p.poll(r.createTaskListener()).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()); }
private boolean runPolling() { try { // to make sure that the log file contains up-to-date text, // don't do buffering. StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on "+ DateFormat.getDateTimeInstance().format(new Date())); boolean result = job().poll(listener).hasChanges(); logger.println("Done. Took "+ Util.getTimeSpanString(System.currentTimeMillis()-start)); if(result) logger.println("Changes found"); else logger.println("No changes"); return result; } catch (Error | RuntimeException e) { Functions.printStackTrace(e, listener.error("Failed to record SCM polling for " + job)); LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e); throw e; } finally { listener.close(); } } catch (IOException e) { LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e); return false; } }
return new PollingResult(baseline, new SVNRevisionState(revs), significantChanges ? Change.SIGNIFICANT : changes ? Change.INSIGNIFICANT : Change.NONE);
@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()); }
new UpdateUpdater(), null, ".*/bar", "", "", "", ""); FreeStyleProject p = r.createFreeStyleProject("testExcludedRegions"); p.setScm(scm); r.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); assertFalse(p.poll(r.createTaskListener()).hasChanges()); p.poll(r.createTaskListener()).hasChanges()); p.poll(r.createTaskListener()).hasChanges());
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()); } }
return 0; if (!item.poll(new StreamTaskListener(stdout, getClientCharset())).hasChanges()) return 0; throw new IllegalStateException(BUILD_SCHEDULING_REFUSED); Run<?,?> b = f.waitForStart(); // wait for the start stdout.println("Started "+b.getFullDisplayName()); stdout.flush(); f.get(); // wait for the completion stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult()); return b.getResult().ordinal; } else { f.cancel(true); Exception myException = new AbortException(); myException.initCause(e);
/** * Checks if there's any update in SCM, and returns true if any is found. * * @deprecated as of 1.346 * Use {@link #poll(TaskListener)} instead. */ @Deprecated public boolean pollSCMChanges( TaskListener listener ) { return poll(listener).hasChanges(); }