@@ -13,14 +13,26 @@ initscript {
13
13
boolean USE_ARTIFACTORY = false
14
14
15
15
if (System . getenv(' VAULT_ADDR' ) == null ) {
16
+ // When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
17
+ if (System . getenv(' CI' ) == null ) {
18
+ return
19
+ }
20
+
16
21
throw new GradleException (" You must set the VAULT_ADDR environment variable to use this init script." )
17
22
}
18
23
19
24
if (System . getenv(' VAULT_ROLE_ID' ) == null && System . getenv(' VAULT_SECRET_ID' ) == null && System . getenv(' VAULT_TOKEN' ) == null ) {
25
+ // When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
26
+ if (System . getenv(' CI' ) == null ) {
27
+ return
28
+ }
29
+
20
30
throw new GradleException (" You must set either the VAULT_ROLE_ID and VAULT_SECRET_ID environment variables, " +
21
31
" or the VAULT_TOKEN environment variable to use this init script." )
22
32
}
23
33
34
+ final String vaultPathPrefix = System . getenv(' VAULT_ADDR' ) ==~ / .+vault-ci.+\. dev.*/ ? " secret/ci/elastic-elasticsearch/migrated" : " secret/elasticsearch-ci"
35
+
24
36
final String vaultToken = System . getenv(' VAULT_TOKEN' ) ?: new Vault (
25
37
new VaultConfig ()
26
38
.address(System . env. VAULT_ADDR )
@@ -44,8 +56,8 @@ final Vault vault = new Vault(
44
56
45
57
if (USE_ARTIFACTORY ) {
46
58
final Map<String , String > artifactoryCredentials = vault. logical()
47
- .read(" secret/elasticsearch-ci /artifactory.elstc.co" )
48
- .getData();
59
+ .read(" ${ vaultPathPrefix } /artifactory.elstc.co" )
60
+ .getData()
49
61
logger. info(" Using elastic artifactory repos" )
50
62
Closure configCache = {
51
63
return {
@@ -78,10 +90,10 @@ if (USE_ARTIFACTORY) {
78
90
}
79
91
}
80
92
81
- projectsLoaded {
82
- rootProject {
83
- project . pluginManager . withPlugin( ' com.gradle.build-scan ' ) {
84
- buildScan . server = ' https://gradle-enterprise.elastic.co'
93
+ gradle . settingsEvaluated { settings ->
94
+ settings . pluginManager . withPlugin( " com.gradle.enterprise " ) {
95
+ settings . gradleEnterprise {
96
+ server = ' https://gradle-enterprise.elastic.co'
85
97
}
86
98
}
87
99
}
@@ -91,9 +103,9 @@ final String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.u
91
103
final boolean buildCachePush = Boolean . valueOf(System . getProperty(' org.elasticsearch.build.cache.push' , ' false' ))
92
104
93
105
if (buildCacheUrl) {
94
- final Map<String , String > buildCacheCredentials = vault. logical()
95
- .read(" secret/elasticsearch-ci /gradle-build-cache" )
96
- .getData();
106
+ final Map<String , String > buildCacheCredentials = System . getenv( " GRADLE_BUILD_CACHE_USERNAME " ) ? [:] : vault. logical()
107
+ .read(" ${ vaultPathPrefix } /gradle-build-cache" )
108
+ .getData()
97
109
gradle. settingsEvaluated { settings ->
98
110
settings. buildCache {
99
111
local {
@@ -104,8 +116,8 @@ if (buildCacheUrl) {
104
116
url = buildCacheUrl
105
117
push = buildCachePush
106
118
credentials {
107
- username = buildCacheCredentials. get(" username" )
108
- password = buildCacheCredentials. get(" password" )
119
+ username = System . getenv( " GRADLE_BUILD_CACHE_USERNAME " ) ?: buildCacheCredentials. get(" username" )
120
+ password = System . getenv( " GRADLE_BUILD_CACHE_PASSWORD " ) ?: buildCacheCredentials. get(" password" )
109
121
}
110
122
}
111
123
}
0 commit comments