Skip to content

Commit 4e27747

Browse files
authored
DEVPROD-3821 Complete Bamboo server setup before installing agent (#1097)
1 parent 69dfea3 commit 4e27747

1 file changed

Lines changed: 70 additions & 6 deletions

File tree

src/test/scripts/kind/deploy_app.sh

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ deploy_app() {
285285
${MISC_OVERRIDES}
286286

287287
if [ ${DC_APP} == "bamboo" ]; then
288+
wait_for_bamboo_setup
289+
288290
if [[ -n "${OPENSHIFT_VALUES}" ]]; then
289291
OPENSHIFT_VALUES="--set openshift.runWithRestrictedSCC=true"
290292
fi
@@ -297,7 +299,26 @@ deploy_app() {
297299
${OPENSHIFT_VALUES} \
298300
${AGENT_OVERRIDES} \
299301
--wait --timeout=180s \
300-
--debug
302+
--debug || {
303+
echo "[ERROR]: Bamboo agent deployment failed."
304+
echo "[DEBUG]: Bamboo agent pods:"
305+
kubectl get pods -n atlassian -l app.kubernetes.io/name=bamboo-agent -o wide 2>/dev/null || true
306+
echo "[DEBUG]: Bamboo agent pod describe:"
307+
kubectl describe pods -n atlassian -l app.kubernetes.io/name=bamboo-agent 2>/dev/null || true
308+
echo "[DEBUG]: Bamboo agent container logs (last 500 lines):"
309+
for pod in $(kubectl get pods -n atlassian -l app.kubernetes.io/name=bamboo-agent --no-headers -o custom-columns=":metadata.name" 2>/dev/null); do
310+
echo "--- Logs from ${pod} ---"
311+
kubectl logs "${pod}" -n atlassian --tail=500 2>/dev/null || true
312+
done
313+
echo "[DEBUG]: Bamboo server container logs (last 500 lines):"
314+
for pod in $(kubectl get pods -n atlassian -l app.kubernetes.io/name=bamboo --no-headers -o custom-columns=":metadata.name" 2>/dev/null); do
315+
echo "--- Logs from ${pod} ---"
316+
kubectl logs "${pod}" -n atlassian --tail=500 2>/dev/null || true
317+
done
318+
echo "[DEBUG]: Events in atlassian namespace (last 50):"
319+
kubectl get events -n atlassian --sort-by='.lastTimestamp' 2>/dev/null | tail -50 || true
320+
exit 1
321+
}
301322
fi
302323

303324
# Deploy Bitbucket Mirror in KinD only. MicroShift can't handle too many pods/processes
@@ -318,6 +339,53 @@ deploy_app() {
318339
fi
319340
}
320341

342+
# Resolve the ingress/gateway hostname based on the deployment environment.
343+
get_routing_hostname() {
344+
if [ -n "${OPENSHIFT_VALUES}" ]; then
345+
echo "atlassian.apps.crc.testing"
346+
else
347+
echo "localhost"
348+
fi
349+
}
350+
351+
# Wait for Bamboo server's unattended setup wizard to complete.
352+
# Bamboo 12+ uses absolute redirects during setup, which prevents the agent from
353+
# triggering setup advancement (unlike Bamboo 11 which used relative redirects).
354+
# We poll GET / — during setup it redirects to /bootstrap/selectSetupStep.action,
355+
# after setup it redirects to /userlogin.action. Following the redirect chain
356+
# during setup triggers the wizard to advance to the next step.
357+
wait_for_bamboo_setup() {
358+
echo "[INFO]: Waiting for Bamboo server unattended setup to complete..."
359+
SETUP_HOSTNAME=$(get_routing_hostname)
360+
SETUP_TIMEOUT=300
361+
SETUP_ELAPSED=0
362+
while [ ${SETUP_ELAPSED} -lt ${SETUP_TIMEOUT} ]; do
363+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}|%{redirect_url}" --max-redirs 0 http://${SETUP_HOSTNAME}/ 2>/dev/null || echo "000|")
364+
HTTP_CODE=$(echo "$RESPONSE" | cut -d'|' -f1)
365+
REDIRECT_URL=$(echo "$RESPONSE" | cut -d'|' -f2)
366+
367+
if echo "${REDIRECT_URL}" | grep -q "bootstrap\|setup"; then
368+
# Server is in setup mode — trigger setup advancement by following the redirect chain
369+
curl -s -o /dev/null -L --max-redirs 10 http://${SETUP_HOSTNAME}/ 2>/dev/null || true
370+
echo "[INFO]: Bamboo setup in progress (HTTP ${HTTP_CODE}${REDIRECT_URL}). Triggering setup... (${SETUP_ELAPSED}s/${SETUP_TIMEOUT}s)"
371+
elif [ "${HTTP_CODE}" = "302" ] && echo "${REDIRECT_URL}" | grep -q "userlogin"; then
372+
echo "[INFO]: Bamboo server setup complete (redirecting to login page)"
373+
return 0
374+
elif [ "${HTTP_CODE}" = "000" ]; then
375+
echo "[INFO]: Bamboo server not reachable yet. Waiting... (${SETUP_ELAPSED}s/${SETUP_TIMEOUT}s)"
376+
else
377+
echo "[INFO]: Bamboo server responded with HTTP ${HTTP_CODE}. Waiting... (${SETUP_ELAPSED}s/${SETUP_TIMEOUT}s)"
378+
fi
379+
380+
sleep 10
381+
SETUP_ELAPSED=$((SETUP_ELAPSED + 10))
382+
done
383+
384+
echo "[WARNING]: Bamboo setup did not complete within ${SETUP_TIMEOUT}s. Proceeding with agent deployment anyway."
385+
echo "[DEBUG]: Full response from GET / with redirects:"
386+
curl -v -s -L --max-redirs 10 http://${SETUP_HOSTNAME}/ 2>&1 || true
387+
}
388+
321389
verify_ingress() {
322390
STATUS_ENDPOINT_PATH="status"
323391
if [ ${DC_APP} == "bamboo" ]; then
@@ -328,11 +396,7 @@ verify_ingress() {
328396
echo "[INFO]: Checking ${DC_APP} status"
329397
# give ingress controller a few seconds before polling
330398
sleep 5
331-
if [ -n "${OPENSHIFT_VALUES}" ]; then
332-
HOSTNAME="atlassian.apps.crc.testing"
333-
else
334-
HOSTNAME="localhost"
335-
fi
399+
HOSTNAME=$(get_routing_hostname)
336400
for i in {1..10}; do
337401
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://${HOSTNAME}/${STATUS_ENDPOINT_PATH})
338402
if [ $STATUS -ne 200 ]; then

0 commit comments

Comments
 (0)