12
12
# 3. If this is not a PR build, upload the build to the artifacts directory on
13
13
# S3 that subsequent Java builds will download the C++ components from
14
14
15
- $ErrorActionPreference = " Stop"
16
-
17
15
# If this isn't a PR build then obtain credentials from Vault
18
16
if (! (Test-Path Env:PR_AUTHOR)) {
19
17
# Generate a Vault token
@@ -22,19 +20,31 @@ if (!(Test-Path Env:PR_AUTHOR)) {
22
20
Exit $LastExitCode
23
21
}
24
22
25
- $AwsCreds = & vault read - format= json - field= data aws- dev/ creds/ prelertartifacts
26
- if ($LastExitCode -ne 0 ) {
27
- Exit $LastExitCode
28
- }
29
- $Env: ML_AWS_ACCESS_KEY = (echo $AwsCreds | jq - r " .access_key" )
30
- $Env: ML_AWS_SECRET_KEY = (echo $AwsCreds | jq - r " .secret_key" )
23
+ $Failures = 0
24
+ do {
25
+ $AwsCreds = & vault read - format= json - field= data aws- dev/ creds/ prelertartifacts
26
+ if ($LastExitCode -eq 0 ) {
27
+ $Env: ML_AWS_ACCESS_KEY = (echo $AwsCreds | jq - r " .access_key" )
28
+ $Env: ML_AWS_SECRET_KEY = (echo $AwsCreds | jq - r " .secret_key" )
29
+ } else {
30
+ $Failures ++
31
+ Write-Output " Attempt $Failures to get AWS credentials failed"
32
+ }
33
+ } while (($Failures -lt 3 ) -and [string ]::IsNullOrEmpty($Env: ML_AWS_ACCESS_KEY ))
31
34
32
35
# Remove VAULT_* environment variables
33
36
Remove-Item Env:VAULT_TOKEN
34
37
Remove-Item Env:VAULT_ROLE_ID
35
38
Remove-Item Env:VAULT_SECRET_ID
39
+
40
+ if ([string ]::IsNullOrEmpty($Env: ML_AWS_ACCESS_KEY ) -or [string ]::IsNullOrEmpty($Env: ML_AWS_SECRET_KEY )) {
41
+ Write-Output " Exiting after failing to get AWS credentials $Failures times"
42
+ Exit 1
43
+ }
36
44
}
37
45
46
+ $ErrorActionPreference = " Stop"
47
+
38
48
# Change directory to the top level of the repo
39
49
Set-Location - Path " $PSScriptRoot \.."
40
50
0 commit comments