Skip to content

Commit c4143ac

Browse files
add a retry to retrieve the CIRCLE_OIDC_TOKEN if it doesn't exist in … (#221)
* add a retry to retrieve the CIRCLE_OIDC_TOKEN if it doesn't exist in the job * Update orbs and shellcheck for bash --------- Co-authored-by: marboledacci <[email protected]>
1 parent c314905 commit c4143ac

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: 2.1
22
setup: true
33
orbs:
4-
orb-tools: circleci/orb-tools@12.2
5-
shellcheck: circleci/shellcheck@3.2
4+
orb-tools: circleci/orb-tools@12.3.1
5+
shellcheck: circleci/shellcheck@3.4
66

77
filters: &filters
88
tags:
@@ -18,6 +18,7 @@ workflows:
1818
- orb-tools/review:
1919
filters: *filters
2020
- shellcheck/check:
21+
shell: bash
2122
filters: *filters
2223
- orb-tools/continue:
2324
orb_name: aws-cli

.circleci/test-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2.1
22
orbs:
3-
orb-tools: circleci/orb-tools@12.0
3+
orb-tools: circleci/orb-tools@12.3.1
44
aws-cli: {}
55
filters: &filters
66
tags:

src/scripts/assume_role_with_web_identity.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@ if [ -z "${AWS_CLI_STR_ROLE_SESSION_NAME}" ]; then
1414
exit 1
1515
fi
1616

17-
if [ -z "${CIRCLE_OIDC_TOKEN_V2}" ]; then
18-
echo "OIDC Token cannot be found."
17+
if [ -z "${CIRCLE_OIDC_TOKEN_V2}" ] || [ -z "${CIRCLE_OIDC_TOKEN}" ]; then
18+
for i in {1..3}; do
19+
echo "Attempt $i: Checking OIDC tokens"
20+
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+
echo "Successfully set CIRCLE_OIDC_TOKEN"
23+
echo 'export CIRCLE_OIDC_TOKEN="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
24+
echo 'export CIRCLE_OIDC_TOKEN_V2="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
25+
exit 0
26+
fi
27+
echo "Waiting 1 second before retry"
28+
sleep 1
29+
done
30+
echo "Failed to set CIRCLE_OIDC_TOKEN_V2 after 3 attempts"
1931
exit 1
2032
fi
2133

0 commit comments

Comments
 (0)