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.
  • Loading branch information
shakuzen committed May 20, 2021
1 parent 8ee255e commit bca0d1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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 +108,10 @@ private boolean isBamboo() {
return this.env.containsKey(BAMBOO_RESULTS_ENV_VAR);
}

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

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

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

@Test
void whenCircleCiAndCircleBuildUrlEnvVarsArePresentThenBuildScanHasACiBuildLinkToIt() {
Map<String, String> env = new HashMap<>();
env.put("CIRCLECI", "true");
env.put("CIRCLE_BUILD_URL", "https://circleci.example.com/gh/org/project/123");
new BuildScanConventions(this.processRunner, env).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 bca0d1c

Please sign in to comment.