Skip to content

Commit 1289ba8

Browse files
authored
[7.x][ML] Retry getting AWS credentials in CI builds (#1764)
It's very frustrating if CI builds fail because of a transient failure obtaining AWS credentials for uploading the final output. Backport of #1762
1 parent 63ee672 commit 1289ba8

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

dev-tools/jenkins_ci.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# 3. If this is not a PR build, upload the build to the artifacts directory on
1313
# S3 that subsequent Java builds will download the C++ components from
1414

15-
$ErrorActionPreference="Stop"
16-
1715
# If this isn't a PR build then obtain credentials from Vault
1816
if (!(Test-Path Env:PR_AUTHOR)) {
1917
# Generate a Vault token
@@ -22,19 +20,31 @@ if (!(Test-Path Env:PR_AUTHOR)) {
2220
Exit $LastExitCode
2321
}
2422

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))
3134

3235
# Remove VAULT_* environment variables
3336
Remove-Item Env:VAULT_TOKEN
3437
Remove-Item Env:VAULT_ROLE_ID
3538
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+
}
3644
}
3745

46+
$ErrorActionPreference="Stop"
47+
3848
# Change directory to the top level of the repo
3949
Set-Location -Path "$PSScriptRoot\.."
4050

dev-tools/jenkins_ci.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,25 @@ if [ -z "$PR_AUTHOR" ] ; then
3535
set +x
3636
export VAULT_TOKEN=$(vault write -field=token auth/approle/login role_id="$VAULT_ROLE_ID" secret_id="$VAULT_SECRET_ID")
3737

38-
AWS_CREDS=$(vault read -format=json -field=data aws-dev/creds/prelertartifacts)
39-
export ML_AWS_ACCESS_KEY=$(echo $AWS_CREDS | jq -r '.access_key')
40-
export ML_AWS_SECRET_KEY=$(echo $AWS_CREDS | jq -r '.secret_key')
38+
unset ML_AWS_ACCESS_KEY ML_AWS_SECRET_KEY
39+
FAILURES=0
40+
while [ $FAILURES -lt 3 -a -z "$ML_AWS_ACCESS_KEY" ] ; do
41+
AWS_CREDS=$(vault read -format=json -field=data aws-dev/creds/prelertartifacts)
42+
if [ $? -eq 0 ] ; then
43+
export ML_AWS_ACCESS_KEY=$(echo $AWS_CREDS | jq -r '.access_key')
44+
export ML_AWS_SECRET_KEY=$(echo $AWS_CREDS | jq -r '.secret_key')
45+
else
46+
let FAILURES++
47+
echo "Attempt $FAILURES to get AWS credentials failed"
48+
fi
49+
done
4150

4251
unset VAULT_TOKEN VAULT_ROLE_ID VAULT_SECRET_ID
52+
53+
if [ -z "$ML_AWS_ACCESS_KEY" -o -z "$ML_AWS_SECRET_KEY" ] ; then
54+
echo "Exiting after failing to get AWS credentials $FAILURES times"
55+
exit 1
56+
fi
4357
set -x
4458
fi
4559

@@ -124,7 +138,7 @@ case `uname` in
124138

125139
*)
126140
echo `uname 2>&1` "- unsupported operating system"
127-
exit 1
141+
exit 2
128142
;;
129143
esac
130144

0 commit comments

Comments
 (0)