Skip to content

Commit cdc5909

Browse files
committed
fix(docker): Adding error handling for when both controllers are unreachable.
And making the timeout duration configurable.
1 parent 066d15e commit cdc5909

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

dockerfiles/agent-discovery/find-name.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,20 @@ JENKINS_CONTROLLER="jenkins_controller"
8484
if ! curl -s -f "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
8585
echo "Primary controller not reachable, falling back to multi controller..."
8686
JENKINS_CONTROLLER="multi_jenkins_controller"
87+
if ! curl -s -f "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
88+
echo "Error: Neither primary nor multi controller is reachable"
89+
exit 1
90+
fi
8791
fi
8892

8993
# Check If Jenkins is running or not
9094
# If the message is found, awk exits with a non-zero status (1), and the loop continues.
9195
# If the message is not found, the loop exits, and the "Jenkins is running" message is displayed.
9296
timeout 60 bash -c "until curl -s -f http://${JENKINS_CONTROLLER}:8080/login > /dev/null; do sleep 5; done" && echo "Jenkins is running" || echo "Jenkins is not running"
97+
# The colon (:) is a no-op command in Bash, which means it does nothing and always returns a true exit status. It is often used as a placeholder or to evaluate expressions without executing any commands.
98+
# The ${JENKINS_STARTUP_TIMEOUT:=60} part is a parameter expansion. It checks if the JENKINS_STARTUP_TIMEOUT variable is set and not null. If it is not set, it assigns the value 60 to JENKINS_STARTUP_TIMEOUT
99+
: "${JENKINS_STARTUP_TIMEOUT:=60}" # Default to 60 seconds if not set
100+
timeout "${JENKINS_STARTUP_TIMEOUT}" bash -c "until curl -s -f http://${JENKINS_CONTROLLER}:8080/login > /dev/null; do sleep 5; done" && echo "Jenkins is running" || echo "Jenkins is not running"
93101

94102
echo "Jenkins is ready"
95103
# Get the Jenkins version

0 commit comments

Comments
 (0)