So I wrote Hacking/Parsing Automation Rules with JSON for Fun and Profit a few years ago, but haven't actually done much hacking of rules lately.
But just today I had an interesting challenge:
Ah, this sounds like a job for my favorite tool, jq!
So here's what I did:
jq '[.rules[] | select(.name | contains("CloneRoute"))]' automation-rules-202412121711.json > cloneroutes.json
jq '. | { "cloud":true, "rules": [.rules[] | select(.name | contains("CloneRoute"))] }' automation-rules-202412121711.json > cloneroutes.json
And from there, I opened in the cloneroutes.json file in a text editor and bulk-replaced the Project Id for project X (which was 10618) the one for project Y (10183) in the Scope section for each rule:
"ruleScope": {
"resources": [ "ari:cloud:jira:MYCLOUDID:project/10183" ]
},
I also did a bulk replace of "CloneRoute" with the Project Y key, so that we don't have run into duplicate named rules:
"name": "Y CloneRoute i18n Bugs: Leave in Loc",
Then I did an Import Rules, confirmed that the new Names and Project was correct, selected All, checked the box to "Import rule owners", and boom, click Import.
I guess my point here is I wanted to add another practical use of "hacking" your automation rules with jq.
Yes, it can be a little intimidating, but there is truly a lot of power in the tool.
ALSO! If you didn't want to fully "hack" JSON, you could also use jq to simply reformat rules into something that you could edit by hand.
This:
jq . automation-rules-20241213.json > formattedrules.json
will give you a formattedrules.json that is a lot easier to read. You could even replicate what my longer jq command did by manually looking for rules that start with "CloneRoute" and copy-paste them into a new file, call it: rulestoimport.json
Each rule would start with something like this:
{
"id": 19580617,
"clientKey": "xxxxx-xxxx-xxx-xx-xx",
"name": "CloneRoute Foo Bugs: Leave in Bar",
"state": "ENABLED",
And end with this:
"writeAccessType": "UNRESTRICTED",
"collaborators": [],
"billingType": "NORMAL",
"idUuid": "xyioasdf-sda-asd-sad-asdasdf"
}
So again, you just need to KEEP everything for each rule, and then insert them into this structure:
{ "cloud": true,
"rules": [
HERE IS WHERE ALL THE RULES GO
]
}
Oof. That is a LOT. Sorry. Hope it helps somebody.
Darryl Lee
Sr. Atlassian Systems Engineer
Roku, Inc.
San Jose, CA
191 accepted answers
0 comments