Skip to content

Commit

Permalink
Merge pull request #200 from gradle/gk/captureCiProvider
Browse files Browse the repository at this point in the history
Added capturing CI provider as a custom value
  • Loading branch information
ribafish authored Feb 28, 2024
2 parents c9a76d2 + 7388710 commit 5d3df8b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/gradle/CustomBuildScanEnhancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public CaptureCiMetadataAction(BuildScanApi buildScan) {

private void execute() {
if (isJenkins() || isHudson()) {
String ciProvider = isJenkins() ? "Jenkins" : "Hudson";
String controllerUrlEnvVar = isJenkins() ? "JENKINS_URL" : "HUDSON_URL";

Optional<String> buildUrl = envVariable("BUILD_URL");
Expand All @@ -152,6 +153,7 @@ private void execute() {
Optional<String> stageName = envVariable("STAGE_NAME");
Optional<String> controllerUrl = envVariable(controllerUrlEnvVar);

buildScan.value("CI provider", ciProvider);
buildUrl.ifPresent(url ->
buildScan.link(isJenkins() ? "Jenkins build" : "Hudson build", url));
buildNumber.ifPresent(value ->
Expand All @@ -174,6 +176,7 @@ private void execute() {
}

if (isTeamCity()) {
buildScan.value("CI provider", "TeamCity");
Optional<String> teamcityBuildPropertiesFile = envVariable("TEAMCITY_BUILD_PROPERTIES_FILE");
if (teamcityBuildPropertiesFile.isPresent()) {
Properties buildProperties = readPropertiesFile(teamcityBuildPropertiesFile.get());
Expand Down Expand Up @@ -208,6 +211,7 @@ private void execute() {
}

if (isCircleCI()) {
buildScan.value("CI provider", "CircleCI");
envVariable("CIRCLE_BUILD_URL").ifPresent(url ->
buildScan.link("CircleCI build", url));
envVariable("CIRCLE_BUILD_NUM").ifPresent(value ->
Expand All @@ -219,6 +223,7 @@ private void execute() {
}

if (isBamboo()) {
buildScan.value("CI provider", "Bamboo");
envVariable("bamboo_resultsUrl").ifPresent(url ->
buildScan.link("Bamboo build", url));
envVariable("bamboo_buildNumber").ifPresent(value ->
Expand All @@ -232,6 +237,7 @@ private void execute() {
}

if (isGitHubActions()) {
buildScan.value("CI provider", "GitHub Actions");
Optional<String> gitHubUrl = envVariable("GITHUB_SERVER_URL");
Optional<String> gitRepository = envVariable("GITHUB_REPOSITORY");
Optional<String> gitHubRunId = envVariable("GITHUB_RUN_ID");
Expand All @@ -245,6 +251,7 @@ private void execute() {
}

if (isGitLab()) {
buildScan.value("CI provider", "GitLab");
envVariable("CI_JOB_URL").ifPresent(url ->
buildScan.link("GitLab build", url));
envVariable("CI_PIPELINE_URL").ifPresent(url ->
Expand All @@ -256,6 +263,7 @@ private void execute() {
}

if (isTravis()) {
buildScan.value("CI provider", "Travis");
envVariable("TRAVIS_BUILD_WEB_URL").ifPresent(url ->
buildScan.link("Travis build", url));
envVariable("TRAVIS_BUILD_NUMBER").ifPresent(value ->
Expand All @@ -266,13 +274,15 @@ private void execute() {
}

if (isBitrise()) {
buildScan.value("CI provider", "Bitrise");
envVariable("BITRISE_BUILD_URL").ifPresent(url ->
buildScan.link("Bitrise build", url));
envVariable("BITRISE_BUILD_NUMBER").ifPresent(value ->
buildScan.value("CI build number", value));
}

if (isGoCD()) {
buildScan.value("CI provider", "GoCD");
Optional<String> pipelineName = envVariable("GO_PIPELINE_NAME");
Optional<String> pipelineNumber = envVariable("GO_PIPELINE_COUNTER");
Optional<String> stageName = envVariable("GO_STAGE_NAME");
Expand All @@ -297,6 +307,7 @@ private void execute() {
}

if (isAzurePipelines()) {
buildScan.value("CI provider", "Azure Pipelines");
Optional<String> azureServerUrl = envVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI");
Optional<String> azureProject = envVariable("SYSTEM_TEAMPROJECT");
Optional<String> buildId = envVariable("BUILD_BUILDID");
Expand All @@ -314,6 +325,7 @@ private void execute() {
}

if (isBuildkite()) {
buildScan.value("CI provider", "Buildkite");
envVariable("BUILDKITE_BUILD_URL").ifPresent(url ->
buildScan.link("Buildkite build", url));
envVariable("BUILDKITE_COMMAND").ifPresent(command ->
Expand Down

0 comments on commit 5d3df8b

Please sign in to comment.