Created
October 30, 2019 12:18
-
-
Save cwansart/4d09067d900cd033379fd44b8901e30a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
jenkins_master_is_up() { | |
status=$(curl -s -o /dev/null -w "%{http_code}" $1) | |
if [[ "$status" -eq 200 ]]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
autoconnect() { | |
JENKINS_URL=$1 | |
MAX_TRIES=10 | |
connect_counter=0 | |
echo "Trying to connect to master on $JENKINS_URL" | |
while ! jenkins_master_is_up $JENKINS_URL && [[ $connect_counter -lt $MAX_TRIES ]]; do | |
((connect_counter++)) | |
echo "Attempt $connect_counter" | |
sleep 3 | |
done | |
if [[ $connect_counter -eq $MAX_TRIES ]]; then | |
echo "Failed after $MAX_TRIES attempts to connect to the Jenkins master." | |
echo "Slave won't attempt to automatically connect again." | |
fi | |
} | |
if [[ -z $JENKINS_SERVICE_HOST || -z $JENKINS_SERVICE_PORT ]]; then | |
echo "JENKINS_SERVICE_HOST or JENKINS_SERVICE_PORT not set." | |
echo "Script won't attempt to autoconnect to Jenkins master." | |
else | |
JENKINS_URL="http://$JENKINS_SERVICE_HOST:$JENKINS_SERVICE_PORT" | |
echo "Trying to auto connect to Jenkins master on $JENKINS_URL" | |
autoconnect $JENKINS_URL | |
fi | |
/usr/sbin/sshd -D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment