Skip to content

Commit 79e8643

Browse files
committed
BUILD-11961 Poll edge Artifactory until token returns HTTP 200
Replace the fixed 10s sleep with a shared retry loop against a protected storage API so builds proceed as soon as federation syncs.
1 parent 54a2cf4 commit 79e8643

4 files changed

Lines changed: 62 additions & 21 deletions

File tree

config-maven/action.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,7 @@ runs:
145145
shell: bash
146146
env:
147147
REPOX_URL: ${{ inputs.repox-url }}
148-
run: |
149-
if [[ "$REPOX_URL" == *jfrog.io* ]]; then
150-
echo "Skipping token sync wait for SaaS Repox ($REPOX_URL)"
151-
exit 0
152-
fi
153-
echo "Waiting 10s for Artifactory token federation sync to the edge node"
154-
sleep 10
148+
run: "$(dirname "$ACTION_PATH_CONFIG_MAVEN")/shared/wait_artifactory_token_sync.sh"
155149

156150
- name: Configure Maven settings and set repository URL
157151
if: steps.config-maven-completed.outputs.skip != 'true'

config-npm/action.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,10 @@ runs:
103103
shell: bash
104104
env:
105105
REPOX_URL: ${{ inputs.repox-url }}
106-
run: |
107-
if [[ "$REPOX_URL" == *jfrog.io* ]]; then
108-
echo "Skipping token sync wait for SaaS Repox ($REPOX_URL)"
109-
exit 0
110-
fi
111-
echo "Waiting 10s for Artifactory token federation sync to the edge node"
112-
sleep 10
106+
ARTIFACTORY_URL: ${{ format('{0}/artifactory', inputs.repox-url) }}
107+
ARTIFACTORY_USERNAME: ${{ steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_USERNAME || '' }}
108+
ARTIFACTORY_ACCESS_TOKEN: ${{ steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN || '' }}
109+
run: "$(dirname "$ACTION_PATH_CONFIG_NPM")/shared/wait_artifactory_token_sync.sh"
113110

114111
- name: Configure NPM authentication
115112
if: steps.config-npm-completed.outputs.skip != 'true'

config-uv/action.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,10 @@ runs:
116116
shell: bash
117117
env:
118118
REPOX_URL: ${{ inputs.repox-url }}
119-
run: |
120-
if [[ "$REPOX_URL" == *jfrog.io* ]]; then
121-
echo "Skipping token sync wait for SaaS Repox ($REPOX_URL)"
122-
exit 0
123-
fi
124-
echo "Waiting 10s for Artifactory token federation sync to the edge node"
125-
sleep 10
119+
ARTIFACTORY_URL: ${{ format('{0}/artifactory', inputs.repox-url) }}
120+
ARTIFACTORY_USERNAME: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_USERNAME }}
121+
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
122+
run: "$(dirname "$ACTION_PATH_CONFIG_UV")/shared/wait_artifactory_token_sync.sh"
126123

127124
- name: Configure uv authentication
128125
if: steps.config-uv-completed.outputs.skip != 'true'
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# Wait until a SaaS-minted Artifactory token is accepted by an edge node.
3+
#
4+
# /api/system/ping is anonymous; use a protected storage API that validates the token.
5+
#
6+
# Required environment variables:
7+
# - ARTIFACTORY_URL: Artifactory base URL (…/artifactory)
8+
# - ARTIFACTORY_USERNAME: Artifactory username
9+
# - ARTIFACTORY_ACCESS_TOKEN: Artifactory access token
10+
#
11+
# Optional:
12+
# - REPOX_URL: Instance URL used to skip the wait for SaaS (jfrog.io)
13+
14+
set -euo pipefail
15+
16+
REPOX_URL="${REPOX_URL:-${ARTIFACTORY_URL:-}}"
17+
if [[ "$REPOX_URL" == *jfrog.io* ]]; then
18+
echo "Skipping token sync wait for SaaS Repox ($REPOX_URL)"
19+
exit 0
20+
fi
21+
22+
if [[ -z "${ARTIFACTORY_URL:-}" || -z "${ARTIFACTORY_USERNAME:-}" || -z "${ARTIFACTORY_ACCESS_TOKEN:-}" ]]; then
23+
echo "::error title=Missing Artifactory credentials::Cannot wait for token sync without credentials"
24+
exit 1
25+
fi
26+
27+
check_url="${ARTIFACTORY_URL%/}/api/storage/sonarsource-qa"
28+
max_attempts=60
29+
sleep_seconds=5
30+
attempt=0
31+
32+
echo "Waiting for Artifactory token federation sync at $check_url (up to $((max_attempts * sleep_seconds))s)"
33+
34+
while true; do
35+
attempt=$((attempt + 1))
36+
http_code="$(curl -sS -o /dev/null -w '%{http_code}' \
37+
-u "${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}" \
38+
"$check_url" || echo "000")"
39+
40+
if [[ "$http_code" == "200" ]]; then
41+
echo "Artifactory accepted credentials after ${attempt} attempt(s) (HTTP 200)"
42+
exit 0
43+
fi
44+
45+
if (( attempt >= max_attempts )); then
46+
echo "::error title=Artifactory token sync timeout::Credentials were not accepted by $check_url" \
47+
"within $((max_attempts * sleep_seconds))s (last HTTP ${http_code})"
48+
exit 1
49+
fi
50+
51+
echo "Attempt ${attempt}/${max_attempts}: HTTP ${http_code}, retrying in ${sleep_seconds}s..."
52+
sleep "$sleep_seconds"
53+
done

0 commit comments

Comments
 (0)