Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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