+minion_in_jenkins() {
+ # Usage: check_stack_in_jenkins STACK_NAME JENKINS_URL [JENKINS_URL...]
+ # Returns: 0 If stack is in Jenkins and 1 if stack is not in Jenkins.
+
+ MINION="${1}"
+
+ minions=()
+ for jenkins in "${@:2}"; do
+ JENKINS_URL="$jenkins/computer/api/json?tree=computer[displayName]"
+ resp=$(curl -s -w "\\n\\n%{http_code}" --globoff -H "Content-Type:application/json" "$JENKINS_URL")
+ json_data=$(echo "$resp" | head -n1)
+ #status=$(echo "$resp" | awk 'END {print $NF}')
+
+ # We purposely want to wordsplit here to combine the arrays
+ # shellcheck disable=SC2206,SC2207
+ minions=(${minions[@]} $(echo "$json_data" | \
+ jq -r '.computer[].displayName' | grep -v master)
+ )
+ done
+
+ if [[ "${minions[*]}" =~ $MINION ]]; then
+ return 0
+ fi
+
+ return 1
+}
+