From 240f2fb2c8edb11d651d5cd47f1a9a9b0f8a3f68 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Sun, 12 Jan 2020 13:43:51 +0100 Subject: [PATCH] Pass CI branch parameter to build scan See gh-19658 --- ci/pipeline.yml | 3 +++ ci/tasks/build-project.yml | 1 + gradle/build-scan-user-data.gradle | 10 +++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index e8474d8c63..6274f7f605 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -210,6 +210,7 @@ jobs: image: spring-boot-ci-image file: git-repo/ci/tasks/build-project.yml params: + BRANCH: ((branch)) GRADLE_ENTERPRISE_ACCESS_KEY: ((gradle_enterprise_secret_access_key)) GRADLE_ENTERPRISE_CACHE_USER: ((gradle_enterprise_cache_user.username)) GRADLE_ENTERPRISE_CACHE_PASSWORD: ((gradle_enterprise_cache_user.password)) @@ -299,6 +300,7 @@ jobs: image: spring-boot-jdk11-ci-image file: git-repo/ci/tasks/build-project.yml params: + BRANCH: ((branch)) GRADLE_ENTERPRISE_ACCESS_KEY: ((gradle_enterprise_secret_access_key)) GRADLE_ENTERPRISE_CACHE_USER: ((gradle_enterprise_cache_user.username)) GRADLE_ENTERPRISE_CACHE_PASSWORD: ((gradle_enterprise_cache_user.password)) @@ -336,6 +338,7 @@ jobs: image: spring-boot-jdk13-ci-image file: git-repo/ci/tasks/build-project.yml params: + BRANCH: ((branch)) GRADLE_ENTERPRISE_ACCESS_KEY: ((gradle_enterprise_secret_access_key)) GRADLE_ENTERPRISE_CACHE_USER: ((gradle_enterprise_cache_user.username)) GRADLE_ENTERPRISE_CACHE_PASSWORD: ((gradle_enterprise_cache_user.password)) diff --git a/ci/tasks/build-project.yml b/ci/tasks/build-project.yml index 26fdfb50b0..8236e2bb87 100644 --- a/ci/tasks/build-project.yml +++ b/ci/tasks/build-project.yml @@ -9,6 +9,7 @@ caches: - path: gradle - path: embedmongo params: + BRANCH: CI: true GRADLE_ENTERPRISE_ACCESS_KEY: GRADLE_ENTERPRISE_CACHE_USERNAME: diff --git a/gradle/build-scan-user-data.gradle b/gradle/build-scan-user-data.gradle index 7b8740f966..53ca00634c 100644 --- a/gradle/build-scan-user-data.gradle +++ b/gradle/build-scan-user-data.gradle @@ -27,7 +27,7 @@ void tagCiOrLocal() { void addGitMetadata() { gradleEnterprise.buildScan.background { def gitCommitId = execAndGetStdout('git', 'rev-parse', '--short=8', '--verify', 'HEAD') - def gitBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD') + def gitBranchName = getBranch() def gitStatus = execAndGetStdout('git', 'status', '--porcelain') if(gitCommitId) { @@ -50,6 +50,14 @@ boolean isCi() { System.getenv('CI') } +String getBranch() { + def branch = System.getenv('BRANCH') + if (branch != null && !branch.isEmpty()) { + return branch + } + return execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD') +} + String execAndGetStdout(String... args) { def stdout = new ByteArrayOutputStream() exec {