|
| 1 | +tagOs() |
| 2 | +tagIde() |
| 3 | +tagCiOrLocal() |
| 4 | +addCiMetadata() |
| 5 | +addGitMetadata() |
| 6 | +addTestTaskMetadata() |
| 7 | + |
| 8 | +void tagOs() { |
| 9 | + buildScan.tag System.getProperty('os.name') |
| 10 | +} |
| 11 | + |
| 12 | +void tagIde() { |
| 13 | + if (System.getProperty('idea.version')) { |
| 14 | + buildScan.tag 'IntelliJ IDEA' |
| 15 | + } else if (System.getProperty('eclipse.buildId')) { |
| 16 | + buildScan.tag 'Eclipse' |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +void tagCiOrLocal() { |
| 21 | + buildScan.tag(isCi() ? 'CI' : 'LOCAL') |
| 22 | +} |
| 23 | + |
| 24 | +void addGitMetadata() { |
| 25 | + buildScan.background { |
| 26 | + def gitCommitId = execAndGetStdout('git', 'rev-parse', '--short=8', '--verify', 'HEAD') |
| 27 | + def gitBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD') |
| 28 | + def gitStatus = execAndGetStdout('git', 'status', '--porcelain') |
| 29 | + |
| 30 | + if(gitCommitId) { |
| 31 | + def commitIdLabel = 'Git Commit ID' |
| 32 | + value commitIdLabel, gitCommitId |
| 33 | + link 'Git commit build scans', customValueSearchUrl([(commitIdLabel): gitCommitId]) |
| 34 | + } |
| 35 | + if (gitBranchName) { |
| 36 | + tag gitBranchName |
| 37 | + value 'Git branch', gitBranchName |
| 38 | + } |
| 39 | + if (gitStatus) { |
| 40 | + tag 'dirty' |
| 41 | + value 'Git status', gitStatus |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +void addCiMetadata() { |
| 47 | + def ciBuild = 'CI BUILD' |
| 48 | + if (isBamboo()) { |
| 49 | + buildScan.link ciBuild, System.getenv('bamboo_resultsUrl') |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void addTestTaskMetadata() { |
| 54 | + allprojects { |
| 55 | + tasks.withType(Test) { test -> |
| 56 | + doFirst { |
| 57 | + buildScan.value "Test#maxParallelForks[${test.path}]", test.maxParallelForks.toString() |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +boolean isCi() { |
| 64 | + isBamboo() |
| 65 | +} |
| 66 | + |
| 67 | +boolean isBamboo() { |
| 68 | + System.getenv('bamboo_resultsUrl') |
| 69 | +} |
| 70 | + |
| 71 | +String execAndGetStdout(String... args) { |
| 72 | + def stdout = new ByteArrayOutputStream() |
| 73 | + exec { |
| 74 | + commandLine(args) |
| 75 | + standardOutput = stdout |
| 76 | + } |
| 77 | + return stdout.toString().trim() |
| 78 | +} |
| 79 | + |
| 80 | +String customValueSearchUrl(Map<String, String> search) { |
| 81 | + def query = search.collect { name, value -> |
| 82 | + "search.names=${encodeURL(name)}&search.values=${encodeURL(value)}" |
| 83 | + }.join('&') |
| 84 | + |
| 85 | + "$buildScan.server/scans?$query" |
| 86 | +} |
| 87 | + |
| 88 | +String encodeURL(String url) { |
| 89 | + URLEncoder.encode(url, 'UTF-8') |
| 90 | +} |
0 commit comments