1+ import nebula.plugin.info.scm.ScmInfoExtension
2+
3+ buildScan {
4+ def jenkinsUrl = System . getenv(' JENKINS_URL' ) ? new URL (System . getenv(' JENKINS_URL' )) : null
5+
6+ // Accept Gradle ToS when project property org.elasticsearch.acceptScanTOS=true or this is an Elastic CI build
7+ if (jenkinsUrl?. host?. endsWith(' elastic.co' ) || Boolean . valueOf(project. findProperty(' org.elasticsearch.acceptScanTOS' ) ?: " false" )) {
8+ termsOfServiceUrl = ' https://gradle.com/terms-of-service'
9+ termsOfServiceAgree = ' yes'
10+ }
11+
12+ // Jenkins-specific build scan metadata
13+ if (jenkinsUrl) {
14+ tag ' CI'
15+ tag System . getenv(' JOB_NAME' )
16+ link ' Jenkins Build' , System . getenv(' BUILD_URL' )
17+ System . getenv(' NODE_LABELS' ). split(' ' ). each {
18+ value ' Jenkins Worker Label' , it
19+ }
20+
21+ // Capture changes included in this CI build except for pull request builds
22+ if (System . getenv(' GIT_COMMIT' ) && System . getenv(' ROOT_BUILD_CAUSE_GHPRBCAUSE' ) == null ) {
23+ background {
24+ def changes = " git diff --name-only ${ System.getenv('GIT_PREVIOUS_COMMIT')} ..${ System.getenv('GIT_COMMIT')} " . execute(). text. trim()
25+ value ' Git Changes' , changes
26+ }
27+ }
28+ } else {
29+ tag ' LOCAL'
30+ }
31+
32+ // Add SCM information
33+ def scmInfo = project. extensions. findByType(ScmInfoExtension )
34+ if (scmInfo && scmInfo. change && scmInfo. branch) {
35+ value ' Git Commit ID' , scmInfo. change
36+ // Don't tag the branch if we are in a detached head state
37+ if (scmInfo. branch ==~ / [0-9a-f]{5,40}/ == false ) {
38+ value ' Git Branch' , scmInfo. branch
39+ tag scmInfo. branch
40+ }
41+ link ' Source' , " https://github.com/elastic/elasticsearch/commit/${ scmInfo.change} "
42+ }
43+ }
0 commit comments