Last active
August 10, 2017 16:26
-
-
Save akshaymankar/72e0264e74c8916a778223ac8c27ac31 to your computer and use it in GitHub Desktop.
HIjack a concourse container by URL
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 -eu | |
print_usage() { | |
echo "Usage: $(basename "$0") <job-url>" | |
} | |
invalid_job_url() { | |
echo "Argument [\"$1\"] isn't a valid job url." | |
} | |
main() { | |
if [ $# -ne 1 ]; then | |
print_usage | |
exit 1 | |
fi | |
if [[ "$1" =~ (https://[^\/]*)/teams/.*/pipelines/(.*)/jobs/([^\/]*)(\/.*|$) ]]; then | |
target_url=${BASH_REMATCH[1]} | |
target=$(fly targets |grep "${target_url}" | awk '{print $1}') | |
if [ -z "$target" ]; then | |
invalid_job_url "$1" | |
exit 1 | |
fi | |
job_name="${BASH_REMATCH[3]}" | |
pipeline_name="${BASH_REMATCH[2]}" | |
fly -t "${target}" hijack -j "${pipeline_name}/${job_name}" | |
else | |
invalid_job_url "$1" | |
exit 1 | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment