Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-6746] Updated to add setting of SVN_MAX_REVISION env #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/hudson/scm/SubversionSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@ public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
}
}

// get the maximum revision which attempts to resolve JENKINS-6746
Long maxrev = new Long(0);
for (Long rev : revisions.values()) if (rev>maxrev) maxrev=rev;
env.put("SVN_MAX_REVISION",maxrev.toString());

} catch (IOException e) {
LOGGER.log(WARNING, "error building environment variables", e);
}
Expand Down
26 changes: 25 additions & 1 deletion src/test/java/hudson/scm/SubversionSCMUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,31 @@ public void shouldSetEnvironmentVariablesWithMultipleSvnModules() throws IOExcep
assertThat(envVars.get("SVN_URL_2"), is("/remotepath2"));
assertThat(envVars.get("SVN_REVISION_2"), is("42"));
}


@SuppressWarnings("deprecation")
@Test
public void shouldSetEnvironmentVariablesMaximumRevision() throws IOException {
// GIVEN an scm with a 2 module locations
SubversionSCM scm = mockSCMForBuildEnvVars();

ModuleLocation[] singleLocation = new ModuleLocation[] {new ModuleLocation("/remotepath", "")};
when(scm.getLocations(any(EnvVars.class), any(AbstractBuild.class))).thenReturn(singleLocation);

Map<String, Long> revisions = new HashMap<String, Long>();
revisions.put("/remotepath", 4711L);
revisions.put("/remotepath2", 42L);
revisions.put("/remotepath3", 9920L);
when(scm.parseSvnRevisionFile(any(AbstractBuild.class))).thenReturn(revisions);

// WHEN envVars are build
AbstractBuild<?,?> build = mock(AbstractBuild.class);
Map<String, String> envVars = new HashMap<String, String>();
scm.buildEnvVars(build, envVars);

// THEN: we have the SVN_MAX_REVISION var
assertThat(envVars.get("SVN_MAX_REVISION"), is("9920"));
}

private SubversionSCM mockSCMForBuildEnvVars() {
SubversionSCM scm = mock(SubversionSCM.class);
doCallRealMethod().when(scm).buildEnvVars(any(AbstractBuild.class), anyMapOf(String.class, String.class));
Expand Down