Skip to content

Commit fed6d0c

Browse files
authored
Update find-name.sh
1 parent 6003341 commit fed6d0c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

dockerfiles/agent-discovery/find-name.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,31 @@ while true; do
7979
sleep 2 # Wait for 5 seconds before the next iteration of the loop.
8080
done
8181

82+
## Check if jenkins_controller is reachable, otherwise fall back to multi_jenkins_controller
83+
JENKINS_CONTROLLER="jenkins_controller"
84+
if ! curl -s -f --max-time 60 "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
85+
echo "Primary controller not reachable, falling back to multi controller..."
86+
JENKINS_CONTROLLER="multi_jenkins_controller"
87+
if ! curl -s -f --max-time 60 "http://${JENKINS_CONTROLLER}:8080/login" > /dev/null; then
88+
echo "Error: Neither primary nor multi controller is reachable"
89+
exit 1
90+
fi
91+
fi
92+
8293
# Check If Jenkins is running or not
8394
# If the message is found, awk exits with a non-zero status (1), and the loop continues.
8495
# If the message is not found, the loop exits, and the "Jenkins is running" message is displayed.
85-
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"
96+
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"
101+
86102
echo "Jenkins is ready"
87103
# Get the Jenkins version
88-
JENKINS_VERSION=$(curl -s -I -k http://admin:admin@jenkins_controller:8080 | grep -i '^X-Jenkins:' | awk '{print $2}')
104+
JENKINS_VERSION=$(curl -s -I -k http://admin:admin@$JENKINS_CONTROLLER:8080 | grep -i '^X-Jenkins:' | awk '{print $2}')
89105
echo "Jenkins version is: $JENKINS_VERSION"
90106

91107
# Use the token in the curl command to reload the configuration
92-
# curl -X POST "http://admin:admin@jenkins_controller:8080/reload-configuration-as-code/?casc-reload-token=$JCASC_TOKEN"
93-
curl -X POST "http://admin:admin@jenkins_controller:8080/reload-configuration-as-code/?casc-reload-token=thisisnotsecure"
108+
# curl -X POST "http://admin:admin@$JENKINS_CONTROLLER:8080/reload-configuration-as-code/?casc-reload-token=$JCASC_TOKEN"
109+
curl -X POST "http://admin:admin@$JENKINS_CONTROLLER:8080/reload-configuration-as-code/?casc-reload-token=thisisnotsecure"

0 commit comments

Comments
 (0)