Skip to content

Commit

Permalink
Fix build scan link log parsing for multiple tasks (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextu committed Apr 24, 2024
1 parent c02a00b commit 565ee9f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
14 changes: 9 additions & 5 deletions pom.xml
Expand Up @@ -35,10 +35,10 @@
</scm>

<properties>
<bamboo.version>7.2.10</bamboo.version>
<bamboo.version>8.2.9</bamboo.version>
<bamboo.data.version>${bamboo.version}</bamboo.data.version>
<bamboo.product.data.path>
${basedir}/src/test/resources/generated-test-resources-692-license-723.zip
${basedir}/src/test/resources/generated-test-resources-8_2_9.zip
</bamboo.product.data.path>
<amps.version>8.13.6</amps.version>
<atlassian.spring.scanner.version>4.0.0</atlassian.spring.scanner.version>
Expand Down Expand Up @@ -405,19 +405,23 @@
</build>

<profiles>
<!--
- Bamboo 9.2.4 introduced a db schema breaking change, requiring to generate specific test resources
- Bamboo 9.3.0 requires Java 11 or 12
-->
<profile>
<id>bamboo924OrLater</id>
<properties>
<bamboo.product.data.path>
${basedir}/src/test/resources/generated-test-resources-923.zip
${basedir}/src/test/resources/generated-test-resources-9_2_13.zip
</bamboo.product.data.path>
</properties>
</profile>
<profile>
<id>bamboo93OrLater</id> <!-- same as bamboo924OrLater, but requires Java 11 -->
<id>bamboo93OrLater</id>
<properties>
<bamboo.product.data.path>
${basedir}/src/test/resources/generated-test-resources-923.zip
${basedir}/src/test/resources/generated-test-resources-9_2_13.zip
</bamboo.product.data.path>
<required.java.version>[11,12)</required.java.version>
</properties>
Expand Down
Expand Up @@ -33,7 +33,7 @@ protected final void setupBuildScansLogInterceptor(BuildContext buildContext) {
BuildLogger buildLogger = buildLoggerManager.getLogger(buildContext.getPlanResultKey());
buildLogger
.getInterceptorStack()
.add(new BuildScanLogScanner(new BuildScanCollector(buildContext)));
.addForJob(new BuildScanLogScanner(new BuildScanCollector(buildContext)));
}

protected final void registerDevelocityResources(BuildContext buildContext, File... resources) {
Expand Down
Expand Up @@ -13,13 +13,11 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.Arrays;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class GradleInjectionTest extends AbstractInjectionTest {
Expand Down Expand Up @@ -186,9 +184,9 @@ void skipsAutoInjectionIfRepositoryShouldBeExcluded(String buildKey) {
void enforceUrlOverridesConfiguredUrlInProject() {
// given
ensurePluginConfiguration(form -> form
.setServer("http://localhost:8888")
.setDevelocityPluginVersion(DEVELOCITY_PLUGIN_VERSION)
.enforceUrl()
.setServer("http://localhost:8888")
.setDevelocityPluginVersion(DEVELOCITY_PLUGIN_VERSION)
.enforceUrl()
);

PlanKey planKey = PlanKeys.getPlanKey(PROJECT_KEY, "GPPA");
Expand All @@ -211,4 +209,27 @@ void enforceUrlOverridesConfiguredUrlInProject() {
assertThat(output, containsString("http://localhost:8888/"));
}

@Test
void buildScanLinksAreDetectedForMultipleTasks() {
// given
ensurePluginConfiguration(form -> form
.setServer(mockDevelocityServer.getAddress())
.setDevelocityPluginVersion(DEVELOCITY_PLUGIN_VERSION)
);

// Project with 2 tasks
PlanKey planKey = PlanKeys.getPlanKey(PROJECT_KEY, "GPMT");
JobKey jobKey = Iterables.getOnlyElement(bambooApi.getJobs(planKey)).getKey();

// when
PlanResultKey planResultKey = triggerBuild(planKey, jobKey);
waitForBuildToFinish(planResultKey);

// then
List<String> buildScans = getBuildScansFromMetadata(planResultKey).map(s -> Arrays.asList(s.split(","))).orElse(null);
assertThat(buildScans, notNullValue());
assertThat(buildScans.size(), equalTo(2));
assertThat(buildScans, everyItem(containsString(mockDevelocityServer.getAddress().toString())));
}

}
Binary file not shown.
Binary file not shown.

0 comments on commit 565ee9f

Please sign in to comment.