Skip to content

Instantly share code, notes, and snippets.

@mrueegg
Created June 23, 2021 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrueegg/58a9837185571cf257bf1f2a528e0baa to your computer and use it in GitHub Desktop.
Save mrueegg/58a9837185571cf257bf1f2a528e0baa to your computer and use it in GitHub Desktop.
Fetching all plan Java specs for a Bamboo project by REST and storing it in Java files
#!/usr/bin/env bash
# see https://jira.atlassian.com/browse/BAM-20237 for more details
BAMBOO_HOSTNAME=$1
BAMBOO_API_TOKEN=$2
PROJECT=$3
json=$(curl "https://${BAMBOO_HOSTNAME}/rest/api/latest/project/${PROJECT}/specs.json" \
--header "Authorization: Bearer ${BAMBOO_API_TOKEN}")
for k in $(jq -r '.spec | keys | .[]' <<< $json); do
spec=$(jq -r ".spec[$k]" <<< $json)
projectKey=$(jq -r '.projectKey' <<< "$spec")
buildKey=$(jq -r '.buildKey' <<< "$spec")
jq -r '.code' <<< "$spec" | tr '\n' '\0' | xargs -0 printf '%b\n' > "${projectKey}-${buildKey}.java"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment