Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
while true; do
# API call to GoCD to retrieve list of agents + status
OUTPUT="$(curl -s "${GOCD_URL}/api/agents" -u "${GOCD_USERNAME}:${GOCD_PASSWORD}" -H 'Accept: application/vnd.go.cd.v4+json')"
# Extract the status of the the current agent from the returned JSON using jq
CUR_STATE="$(echo "${OUTPUT}" | jq -r "._embedded.agents[] | select(.hostname == \"${HOSTNAME}\") | .build_state")"
if [[ "${CUR_STATE}" == "Building" ]] && ! [[ "${CUR_STATE}" == "${PREV_STATE}" ]]; then # if the agent's state has changed from something to Building, protect the instance
aws autoscaling set-instance-protection --region "${EC2_REGION}" --instance-ids "${INSTANCE_ID}" --auto-scaling-group-name "${ASG_NAME}" --protected-from-scale-in &
elif [[ "${PREV_STATE}" == "Building" ]] && ! [[ "${CUR_STATE}" == "${PREV_STATE}" ]]; then # if the agent's state has changed from Building to something else, unprotect it
aws autoscaling set-instance-protection --region "${
@aarongorka
aarongorka / kubectl_idempotent_patch.sh
Created December 18, 2018 02:36
A wrapper script to make `kubectl patch` idempotent
#!/usr/bin/env bash
set +e
result="$(kubectl patch "$@")"
code="$?"
if [[ "$code" != "0" && "$result" == "* not patched" ]]; then
echo "$result" 1>&2
exit "$code"
fi
@aarongorka
aarongorka / gitlab_dag_diagram.py
Last active April 30, 2021 12:33
Prints a PlantUML diagram that shows the DAG of the GitLab pipeline
#!/usr/bin/env python3
"""Prints a PlantUML diagram that shows the DAG of the GitLab pipeline"""
import sys
import yaml
from pprint import pprint
def merge(user, default):
if isinstance(user,dict) and isinstance(default,dict):
for k,v in default.items():