ci(jenkins): avoid brittle agent nodes

This commit is contained in:
jenkins 2026-05-19 18:26:51 -03:00
parent c923be8ff1
commit 2464c61339
3 changed files with 41 additions and 2 deletions

2
Jenkinsfile vendored
View File

@ -19,7 +19,9 @@ spec:
- key: kubernetes.io/hostname - key: kubernetes.io/hostname
operator: NotIn operator: NotIn
values: values:
- titan-04
- titan-06 - titan-06
- titan-11
preferredDuringSchedulingIgnoredDuringExecution: preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100 - weight: 100
preference: preference:

View File

@ -18,7 +18,9 @@ spec:
- key: kubernetes.io/hostname - key: kubernetes.io/hostname
operator: NotIn operator: NotIn
values: values:
- titan-04
- titan-06 - titan-06
- titan-11
preferredDuringSchedulingIgnoredDuringExecution: preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100 - weight: 100
preference: preference:

View File

@ -23,7 +23,14 @@ spec:
- key: kubernetes.io/hostname - key: kubernetes.io/hostname
operator: NotIn operator: NotIn
values: values:
- titan-04
- titan-06 - titan-06
- titan-11
- titan-13
- titan-15
- titan-17
- titan-18
- titan-19
preferredDuringSchedulingIgnoredDuringExecution: preferredDuringSchedulingIgnoredDuringExecution:
- weight: 80 - weight: 80
preference: preference:
@ -125,6 +132,25 @@ spec:
sonar_report="${QUALITY_GATE_SONARQUBE_REPORT:-build/sonarqube-quality-gate.json}" sonar_report="${QUALITY_GATE_SONARQUBE_REPORT:-build/sonarqube-quality-gate.json}"
host="${SONARQUBE_HOST_URL%/}" host="${SONARQUBE_HOST_URL%/}"
query="$(printf '%s' "${SONARQUBE_PROJECT_KEY}" | sed 's/ /%20/g')" query="$(printf '%s' "${SONARQUBE_PROJECT_KEY}" | sed 's/ /%20/g')"
if [ -s .scannerwork/report-task.txt ]; then
task_id="$(awk -F= '$1 == "ceTaskId" {print $2}' .scannerwork/report-task.txt | head -1)"
if [ -n "${task_id}" ]; then
deadline=$((SECONDS + 180))
while [ "${SECONDS}" -lt "${deadline}" ]; do
if [ -n "${SONARQUBE_TOKEN:-}" ]; then
auth="$(printf '%s:' "${SONARQUBE_TOKEN}" | base64 | tr -d '\\n')"
ce_payload="$(curl -fsS -H "Authorization: Basic ${auth}" "${host}/api/ce/task?id=${task_id}" 2>/dev/null || true)"
else
ce_payload="$(curl -fsS "${host}/api/ce/task?id=${task_id}" 2>/dev/null || true)"
fi
ce_status="$(printf '%s' "${ce_payload}" | jq -r '.task.status // empty' 2>/dev/null || true)"
case "${ce_status}" in
SUCCESS|FAILED|CANCELED) break ;;
esac
sleep 3
done
fi
fi
sonar_ok=0 sonar_ok=0
if [ -n "${SONARQUBE_TOKEN:-}" ]; then if [ -n "${SONARQUBE_TOKEN:-}" ]; then
auth="$(printf '%s:' "${SONARQUBE_TOKEN}" | base64 | tr -d '\\n')" auth="$(printf '%s:' "${SONARQUBE_TOKEN}" | base64 | tr -d '\\n')"
@ -144,6 +170,15 @@ spec:
"status": "ERROR", "status": "ERROR",
"error": "sonarqube query failed" "error": "sonarqube query failed"
} }
EOF
fi
sonar_status="$(jq -r '.projectStatus.status // .status // .qualityGate.status // empty' "${sonar_report}" 2>/dev/null || true)"
if [ -z "${sonar_status}" ]; then
cat > "${sonar_report}" <<EOF
{
"status": "ERROR",
"error": "sonarqube response missing projectStatus.status"
}
EOF EOF
fi fi
scan_root=build/data-prepper-supply-chain-scan scan_root=build/data-prepper-supply-chain-scan
@ -333,7 +368,7 @@ EOF
} }
if enabled "${QUALITY_GATE_SONARQUBE_ENFORCE:-1}"; then if enabled "${QUALITY_GATE_SONARQUBE_ENFORCE:-1}"; then
sonar_status="$(jq -r '.status // .projectStatus.status // .qualityGate.status // empty' build/sonarqube-quality-gate.json 2>/dev/null | tr '[:upper:]' '[:lower:]')" sonar_status="$( (jq -r '.projectStatus.status // .status // .qualityGate.status // empty' build/sonarqube-quality-gate.json 2>/dev/null || true) | tr '[:upper:]' '[:lower:]')"
[ -n "${sonar_status}" ] || sonar_status="missing" [ -n "${sonar_status}" ] || sonar_status="missing"
case "${sonar_status}" in case "${sonar_status}" in
ok|pass|passed|success) ;; ok|pass|passed|success) ;;
@ -453,7 +488,7 @@ EOF
fi fi
sonarqube_check="not_applicable" sonarqube_check="not_applicable"
if [ -f build/sonarqube-quality-gate.json ]; then if [ -f build/sonarqube-quality-gate.json ]; then
sonar_status="$(jq -r '.status // .projectStatus.status // .qualityGate.status // empty' build/sonarqube-quality-gate.json 2>/dev/null | tr '[:upper:]' '[:lower:]')" sonar_status="$( (jq -r '.projectStatus.status // .status // .qualityGate.status // empty' build/sonarqube-quality-gate.json 2>/dev/null || true) | tr '[:upper:]' '[:lower:]')"
if [ -n "${sonar_status}" ]; then if [ -n "${sonar_status}" ]; then
case "${sonar_status}" in case "${sonar_status}" in
ok|pass|passed|success) sonarqube_check="ok" ;; ok|pass|passed|success) sonarqube_check="ok" ;;