You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
This is a Bitbucket pipeline that you can utilize to schedule backups and version your Automation Rules. Additionally, you can employ 'sed' to replace tokens, URLs, etc., in order to prepare the JSON for importing into your sandbox/production tenant.
Define DOMAIN and USERTOKEN within the deployment environment scope of the pipeline.
<<bitbucket-pipelines.yml>>
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
name: Backup
deployment: production
script:
- bash download.sh
- COMMIT_MESSAGE=`git log --format=%B -n 1 $BITBUCKET_COMMIT`
- echo $COMMIT_MESSAGE
- git add *
- git commit -m "[skip ci] $COMMIT_MESSAGE"
- git push --force
<<download.sh>>
#!/bin/bash
export cloudId
function getCloudId() {
echo "get cloud ID"
HTTP_RESPONSE=$(
curl --silent --write-out "HTTPSTATUS:%{http_code}" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $USERTOKEN" \
-X GET https://$DOMAIN.atlassian.net/_edge/tenant_info 2>&1 \
)
HTTP_BODY=$(
echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g'
)
HTTP_STATUS=$(
echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://'
)
if [ "$HTTP_STATUS" = "200" ]; then
cloudId=$(echo $HTTP_BODY | jq -r '.cloudId')
else
error $HTTP_BODY $HTTP_STATUS
exit 1
fi
}
function getAutomationRules() {
echo "get Automation Rules of $cloudId in $DOMAIN"
HTTP_RESPONSE=$(
curl --silent --write-out "HTTPSTATUS:%{http_code}" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $USERTOKEN" \
--anyauth \
-X GET "https://$DOMAIN.atlassian.net/gateway/api/automation/internal-api/jira/$cloudId/pro/rest/GLOBAL/rule/export" 2>&1 \
)
HTTP_BODY=$(
echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g'
)
HTTP_STATUS=$(
echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://'
)
if [ "$HTTP_STATUS" = "200" ]; then
echo "$HTTP_BODY" | jq > AutomationRule.json 2>/dev/null
ls -l AutomationRule.json
else
echo $HTTP_BODY $HTTP_STATUS
exit 1
fi
}
getCloudId
getAutomationRules
Luis Plaza Vidaurre
Consultant
San Sebastian, Spain
2 accepted answers
1 comment