|
147 | 147 |
|
148 | 148 | if [[ "${SMART_RETRIES:-}" == "true" && "${BUILDKITE_RETRY_COUNT:-0}" -gt 0 ]]; then |
149 | 149 | echo "--- Resolving previously failed tests" |
150 | | - BUILD_JSON=$(curl -H "Authorization: Bearer $BUILDKITE_API_TOKEN" -X GET "https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_NUMBER}") |
151 | | - ORIGIN_JOB_ID=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg jobId "$BUILDKITE_JOB_ID" ' .jobs[] | select(.id == $jobId) | .retry_source.job_id') |
152 | | - BUILD_SCAN_URL=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg job_id "$ORIGIN_JOB_ID" '.meta_data["build-scan-" + $job_id]') |
153 | | - BUILD_SCAN_ID=$(echo "$BUILD_SCAN_URL" | sed 's|.*/s/||') |
154 | | - DEVELOCITY_FAILED_TEST_API_URL="https://gradle-enterprise.elastic.co/api/tests/build/${BUILD_SCAN_ID}?testOutcomes=failed" |
155 | | - |
156 | | - curl --request GET \ |
157 | | - --url $DEVELOCITY_FAILED_TEST_API_URL \ |
158 | | - --header 'accept: application/json' \ |
159 | | - --header "authorization: Bearer $DEVELOCITY_API_ACCESS_KEY" \ |
160 | | - --header 'content-type: application/json' | gunzip | jq '.' &> failed-tests.json |
| 150 | + if BUILD_JSON=$(curl -H "Authorization: Bearer $BUILDKITE_API_TOKEN" -X GET "https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_NUMBER}" 2>/dev/null); then |
| 151 | + if ORIGIN_JOB_ID=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg jobId "$BUILDKITE_JOB_ID" ' .jobs[] | select(.id == $jobId) | .retry_source.job_id' 2>/dev/null) && [ "$ORIGIN_JOB_ID" != "null" ] && [ -n "$ORIGIN_JOB_ID" ]; then |
| 152 | + if BUILD_SCAN_URL=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg job_id "$ORIGIN_JOB_ID" '.meta_data["build-scan-" + $job_id]' 2>/dev/null) && [ "$BUILD_SCAN_URL" != "null" ] && [ -n "$BUILD_SCAN_URL" ]; then |
| 153 | + BUILD_SCAN_ID=$(echo "$BUILD_SCAN_URL" | sed 's|.*/s/||') |
| 154 | + DEVELOCITY_FAILED_TEST_API_URL="https://gradle-enterprise.elastic.co/api/tests/build/${BUILD_SCAN_ID}?testOutcomes=failed" |
| 155 | + |
| 156 | + if ! curl --request GET \ |
| 157 | + --url $DEVELOCITY_FAILED_TEST_API_URL \ |
| 158 | + --header 'accept: application/json' \ |
| 159 | + --header "authorization: Bearer $DEVELOCITY_API_ACCESS_KEY" \ |
| 160 | + --header 'content-type: application/json' 2>/dev/null | gunzip | jq '.' &> failed-tests.json; then |
| 161 | + echo "Warning: Failed to fetch failed tests from Develocity API" |
| 162 | + fi |
| 163 | + else |
| 164 | + echo "Warning: Could not extract build scan URL from build metadata" |
| 165 | + fi |
| 166 | + else |
| 167 | + echo "Warning: Could not find origin job ID for retry" |
| 168 | + fi |
| 169 | + else |
| 170 | + echo "Warning: Failed to fetch build information from Buildkite API" |
| 171 | + fi |
161 | 172 | fi |
162 | 173 |
|
163 | 174 | # Amazon Linux 2 has DNS resolution issues with resource-based hostnames in EC2 |
|
0 commit comments