Skip to content
Permalink
Browse files

Fixed JENKINS-25544

  • Loading branch information...
MadsNielsen committed Nov 24, 2014
1 parent f7ce714 commit 475dfea4b78097a9f66f89f769122fcf195ce5bc
@@ -400,20 +400,13 @@ public void validateConfiguration(AbstractProject<?, ?> project) throws Unsuppor
//Multiple SCMs plugin.
} else if(Jenkins.getInstance().getPlugin("multiple-scms") != null && project.getScm() instanceof MultiSCM ) {
MultiSCM multiscm = (MultiSCM)project.getScm();
//Count the number of git scm's added in your configuration. We only support 1 git repository. Since having multiple
//Git repositories creates multiple git build data objects.
int gitCounter = 0;

for(SCM scm : multiscm.getConfiguredSCMs()) {
if(scm instanceof GitSCM) {
GitSCM gitMultiScm = (GitSCM)scm;
validateGitScm(gitMultiScm);
gitCounter++;
}
}

if(gitCounter > 1) {
throw new UnsupportedConfigurationException("You have included multiple git scm configurations in your 'Multiple SCMs' configuration. Use one git scm configuration, with multiple repositories");
}
} else {
throw new UnsupportedConfigurationException("We only support 'Git' and 'Multiple SCMs' plugins");
}
@@ -427,13 +420,15 @@ public void validateConfiguration(AbstractProject<?, ?> project) throws Unsuppor
*/
private void validateGitScm(GitSCM scm) throws UnsupportedConfigurationException {
List<UserRemoteConfig> configs = scm.getUserRemoteConfigs();
//The default git configuration. Blank name for remote (defaults to origin) and default value in pretested integration.
//The default git configuration with 1 repository in config. Blank name for remote (defaults to origin) and default value in pretested integration.
boolean isDefault = configs.size() == 1 && StringUtils.isBlank(configs.get(0).getName()) && resolveRepoName().equals("origin");

//If you're not using the standard values.
if(!isDefault) {
for(UserRemoteConfig config : configs) {
if(resolveRepoName().equals(config.getName())) {
//If the configured remote matches...Or the case where you have multiple repos selected with default config
//This also covers the scenario where origin is explicitly named in the configuration.
if(resolveRepoName().equals(config.getName()) || (resolveRepoName().equals("origin") && StringUtils.isBlank(config.getName()) ) ) {
return;
}
}
@@ -72,22 +72,20 @@ public void failWhenRepNameIsBlankAndGitHasMoreThanOneRepo() throws Exception {

jenkinsRule.waitUntilNoActivityUpTo(60000);

int nextBuildNumber = project.getNextBuildNumber();
FreeStyleBuild build = project.getBuildByNumber(nextBuildNumber - 1);

//Show the log for the latest build
String text = jenkinsRule.createWebClient().getPage(build, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");

assertTrue(text.contains(UnsupportedConfigurationException.ILLEGAL_CONFIG_NO_REPO_NAME_DEFINED));

assertTrue(build.getResult().isWorseOrEqualTo(Result.FAILURE));
repository2.close();
if (repository2.getDirectory().getParentFile().exists()) {
FileUtils.deleteQuietly(repository2.getDirectory().getParentFile());
TestUtilsFactory.destroyRepo(repository2);
for(Iterator<FreeStyleBuild> builds = project.getBuilds().iterator(); builds.hasNext();) {
AbstractBuild<?,?> b = builds.next();
String text = jenkinsRule.createWebClient().getPage(b, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");
if(text.contains("push origin :ready/feature_1")) {
assertTrue(b.getResult().equals(Result.SUCCESS));
} else {
assertTrue(b.getResult().equals(Result.NOT_BUILT));
}
}

}

/**
@@ -207,26 +205,23 @@ public void remoteNoRepoSpecifiedWithMoreThan1RepoShouldNotBeSuccessful() throws
project.setScm(gitSCM);
TestUtilsFactory.triggerProject(project);

assertEquals(1, jenkinsRule.jenkins.getQueue().getItems().length);

jenkinsRule.waitUntilNoActivityUpTo(60000);

int nextBuildNumber = project.getNextBuildNumber();
FreeStyleBuild build = project.getBuildByNumber(nextBuildNumber - 1);
TestUtilsFactory.destroyRepo(repository2);

//Show the log for the latest build
String text = jenkinsRule.createWebClient().getPage(build, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");
assertTrue(text.contains(UnsupportedConfigurationException.ILLEGAL_CONFIG_NO_REPO_NAME_DEFINED));

assertTrue(build.getResult().isWorseOrEqualTo(Result.FAILURE));
repository2.close();
if (repository2.getDirectory().getParentFile().exists()) {
FileUtils.deleteQuietly(repository2.getDirectory().getParentFile());
for(Iterator<FreeStyleBuild> builds = project.getBuilds().iterator(); builds.hasNext();) {
AbstractBuild<?,?> b = builds.next();
String text = jenkinsRule.createWebClient().getPage(b, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");
if(text.contains("push origin :ready/feature_1")) {
assertTrue(b.getResult().equals(Result.SUCCESS));
} else {
assertTrue(b.getResult().equals(Result.NOT_BUILT));
}
}

}

/**
@@ -332,7 +327,7 @@ public void validateSquashCommitMessageContents() throws Exception {
try(BuildResultValidator brv = new BuildResultValidator(build, repository1).hasResult(Result.SUCCESS)
.hasHeadCommitContents("Squashed commit of the following", "feature 1 commit 1-ready/feature_1-test-repo1")) {
brv.validate();
}
}

}
}
@@ -56,11 +56,11 @@ public void tearDown() throws Exception {
* Test case 1:
*
* When more than 1 git repository is chosen, and the user has not specified a repository in his pretested configuration, the job
* should fail
* should just use the first repo found. (origin)
* @throws java.lang.Exception
*/
@Test
public void failWithIncorrectConfiguration2RepositoriesWithoutNames() throws Exception {
public void succesWithDefaultConfiguration2RepositoriesWithoutNames() throws Exception {
repository = TestUtilsFactory.createValidRepository("repo1");
Repository repo2 = TestUtilsFactory.createValidRepository("repo2");

@@ -74,15 +74,21 @@ public void failWithIncorrectConfiguration2RepositoriesWithoutNames() throws Exc
jenkinsRule.waitUntilNoActivityUpTo(60000);
TestUtilsFactory.destroyRepo(repo2);

FreeStyleBuild build = project.getBuilds().getFirstBuild();

String text = jenkinsRule.createWebClient().getPage(build, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");
Iterator<FreeStyleBuild> biterator = project.getBuilds().iterator();

assertTrue(text.contains(UnsupportedConfigurationException.ILLEGAL_CONFIG_NO_REPO_NAME_DEFINED));
assertTrue(build.getResult().isWorseThan(Result.SUCCESS));
while(biterator.hasNext()) {
FreeStyleBuild bitstuff = biterator.next();
String text = jenkinsRule.createWebClient().getPage(bitstuff, "console").asText();
System.out.println("=====BUILD-LOG=====");
System.out.println(text);
System.out.println("=====BUILD-LOG=====");
if(text.contains("push origin :ready/feature_1")) {
assertTrue(bitstuff.getResult().equals(Result.SUCCESS));
} else {
assertTrue(bitstuff.getResult().equals(Result.NOT_BUILT));
}

}

}

@@ -155,9 +161,6 @@ public void successWithMatchingRepositoryNames() throws Exception {
}

}

System.out.println("Number of builds "+project.getBuilds().size());


}

0 comments on commit 475dfea

Please sign in to comment.
You can’t perform that action at this time.