Last active
May 9, 2023 20:16
-
-
Save scarytom/5910362 to your computer and use it in GitHub Desktop.
Script to safely de-register jenkins nodes usage: $ remove-nodes-safely.sh my-node-1 my-node-2 my-node-3
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 | |
set -e | |
set -u | |
CI_MASTER_URL="http://ci-1" | |
node_online() { | |
curl --silent "$CI_MASTER_URL/computer/$1/api/json" | grep --silent '"temporarilyOffline":false' | |
} | |
node_busy() { | |
curl --silent "$CI_MASTER_URL/computer/$1/api/json" | grep --silent '"idle":false' | |
} | |
toggle_node_online() { | |
curl --silent "$CI_MASTER_URL/computer/$1/toggleOffline" --request 'POST' --data 'offlineMessage=Pending node re-image' | |
} | |
deregister_node() { | |
curl --silent "$CI_MASTER_URL/computer/$1/doDelete" --request 'POST' --data '' | |
} | |
wait_for_node() { | |
while node_busy $1; do | |
sleep 20 | |
echo -n "." | |
done | |
echo "" | |
} | |
# Mark nodes offline | |
for NODE in "$@" | |
do | |
if node_online $NODE; then | |
echo "Marking node $NODE as offline" | |
toggle_node_online $NODE | |
else | |
echo "Node $NODE is already offline" | |
fi | |
done | |
# Wait for nodes to finish current workload | |
for NODE in "$@" | |
do | |
if node_busy $NODE; then | |
echo "Waiting for node $NODE to finish its current work" | |
wait_for_node $NODE | |
echo "Node $NODE has finished its work" | |
else | |
echo "Node $NODE is not busy" | |
fi | |
done | |
# De-register nodes | |
for NODE in "$@" | |
do | |
echo "Permanently removing $NODE from Jenkins" | |
deregister_node $NODE | |
done |
I did. :) I was just posting it for others who might stumble on this.
On Thu, Apr 16, 2020 at 11:39 Tom Denley ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks for the tip. I don't have any auth on my internal jenkins, but feel
free to copy this script and modify it to suit your needs
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/5910362#gistcomment-3257363>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA7UXOQRKGJSZBX6TE66FTRM5GF5ANCNFSM4MJ733KQ>
.
--
----------------------------------------------------------------------------------------------------------
Sean P. Kane
[email protected]
----------------------------------------------------------------------------------------------------------
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the tip. I don't have any auth on my internal jenkins, but feel free to copy this script and modify it to suit your needs