Skip to content

Commit 04985c2

Browse files
authored
update script to not exit 0 when the OIDC token is set (#224)
1 parent 3145c8a commit 04985c2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/scripts/assume_role_with_web_identity.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@ if [ -z "${AWS_CLI_STR_ROLE_SESSION_NAME}" ]; then
1515
fi
1616

1717
if [ -z "${CIRCLE_OIDC_TOKEN_V2}" ] || [ -z "${CIRCLE_OIDC_TOKEN}" ]; then
18+
TOKEN_SETUP_SUCCESS=false
1819
for i in {1..3}; do
19-
echo "Attempt $i: Checking OIDC tokens"
20+
echo "Attempt $i: Minting OIDC tokens"
2021
CIRCLE_OIDC_TOKEN=$(circleci run oidc get --claims "{\"aud\":\"${CIRCLE_ORGANIZATION_ID}\"}")
21-
if [ -n "$CIRCLE_OIDC_TOKEN" ] || [ -n "$CIRCLE_OIDC_TOKEN_V2" ]; then
22+
if [ -n "$CIRCLE_OIDC_TOKEN" ]; then
2223
echo "Successfully set CIRCLE_OIDC_TOKEN"
2324
echo 'export CIRCLE_OIDC_TOKEN="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
2425
echo 'export CIRCLE_OIDC_TOKEN_V2="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
25-
exit 0
26+
TOKEN_SETUP_SUCCESS=true
27+
break
2628
fi
2729
echo "Waiting 1 second before retry"
2830
sleep 1
2931
done
30-
echo "Failed to set CIRCLE_OIDC_TOKEN_V2 after 3 attempts"
31-
exit 1
32+
33+
if [ "$TOKEN_SETUP_SUCCESS" = false ]; then
34+
echo "Failed to set CIRCLE_OIDC_TOKEN and CIRCLE_OIDC_TOKEN_V2 after 3 attempts. Please try rerunning the worklow."
35+
exit 1
36+
fi
3237
fi
3338

3439
if [ ! "$(command -v aws)" ]; then

0 commit comments

Comments
 (0)