Skip to content

Commit

Permalink
Support build scan link for CircleCI
Browse files Browse the repository at this point in the history
Detects running on CircleCI and configures the build scan with a link
to the CI build job URL.

See gh-31
  • Loading branch information
shakuzen authored and wilkinsona committed Jul 21, 2021
1 parent 8ee255e commit 460d849
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class BuildScanConventions implements Action<BuildScanExtension> {

private static final String BAMBOO_RESULTS_ENV_VAR = "bamboo_resultsUrl";

private static final String CIRCLECI_BUILD_URL_ENV_VAR = "CIRCLE_BUILD_URL";

private final Map<String, String> env;

private final ProcessRunner processRunner;
Expand Down Expand Up @@ -98,7 +100,7 @@ private void tagCiOrLocal(BuildScanExtension buildScan) {
}

private boolean isCi() {
if (isBamboo() || isConcourse() || isJenkins()) {
if (isBamboo() || isCircleCi() || isConcourse() || isJenkins()) {
return true;
}
return false;
Expand All @@ -108,6 +110,10 @@ private boolean isBamboo() {
return this.env.containsKey(BAMBOO_RESULTS_ENV_VAR);
}

private boolean isCircleCi() {
return this.env.containsKey(CIRCLECI_BUILD_URL_ENV_VAR);
}

private boolean isConcourse() {
return this.env.containsKey("CI");
}
Expand Down Expand Up @@ -157,6 +163,9 @@ else if (isJenkins()) {
buildScan.link("CI build", buildUrl);
}
}
else if (isCircleCi()) {
buildScan.link("CI build", this.env.get(CIRCLECI_BUILD_URL_ENV_VAR));
}
}

private RunResult getBranch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ void whenBambooResultEnvVarIsPresentThenBuildScanHasACiBuildLinkToIt() {
assertThat(this.buildScan.links).containsEntry("CI build", "https://bamboo.example.com");
}

@Test
void whenCircleBuildUrlEnvVarIsPresentThenBuildScanHasACiBuildLinkToIt() {
new BuildScanConventions(this.processRunner,
Collections.singletonMap("CIRCLE_BUILD_URL", "https://circleci.example.com/gh/org/project/123"))
.execute(this.buildScan);
assertThat(this.buildScan.links).containsEntry("CI build", "https://circleci.example.com/gh/org/project/123");
}

@Test
void whenJenkinsUrlAndBuildUrlEnvVarsArePresentThenBuildScanHasACiBuildLinkToBuildUrl() {
Map<String, String> env = new HashMap<>();
Expand Down

0 comments on commit 460d849

Please sign in to comment.