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

Support build scan link for CircleCI #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CircleCI also sets an env var CI=true on its builds. I'm not sure if there is a more discerning env var for Concourse. Right now it is not practically an issue since CircleCI is checked before Concourse, but it does feel fragile to potential future changes in this code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concourse doesn't expose any environment variables by default. CI is something that we unimaginatively came up with ourselves and configure in our pipeline. We should change it to something more specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other CI systems that we support in the Common Custom User Data Gradle plugin, we detect the presence of the URL environment variable like so: https://github.com/gradle/gradle-enterprise-build-config-samples/blob/master/common-custom-user-data-gradle-plugin/src/main/java/com/gradle/CustomBuildScanEnhancements.java#L175

}
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