Forum Discussion
creyes17
9 years agoNew Contributor
I heard back from SmartBear that there's no supported way to access the fields as a variable in the Trigger.
I just wanted to post my workaround in case it helps anyone else.
I created this python script to parse JSON, inspired by this stackoverflow post: http://stackoverflow.com/a/8400375 .
(You should be able to replace it with pretty much any json parsing library though).
#! /bin/python import sys,json if len(sys.argv) != 2: sys.stderr.write('Usage: ' + sys.argv[0] + " [requested attribute(s)]\n") sys.stderr.write(' For example: ' + sys.arg[v] + ' "obj[0]"' + "\n") sys.stderr.write(" This would get you the first element of the list in the JSON object passed to the script via stdin\n") obj=json.load(sys.stdin) try: exec "sys.stdout.write(json.dumps(" + sys.argv[1] + "))" except ( AttributeError, KeyError ): sys.stderr.write('Error: Requested JSON attribute does not exist.') sys.stderr.write(' Requested: ' + sys.argv[1]) sys.stderr.write(' JSON: ' + json.dumps(obj))
Assuming that this script lives at /bin/parse-json on the same machine, I wrote the following script to get the internal JiraIssueId field:
#! /bin/bash collaboratorReviewId=$1; if [ -z $collaboratorReviewId ]; then echo "Code Collaborator Review Id is required"; exit 2; fi serverUrl="http://collaborator.server"; commandUrl="$serverUrl/services/json/v1" data='[{"command":"ReviewService.findReviewById","args":{"reviewId":"'$collaboratorReviewId'"}}]'; jiraIssueId=$(curl -X "POST" -H "Content-Type: application/json" -d $data $commandUrl | /bin/parse-json '[field["value"][0] for field in obj[0]["result"]["internalCustomFields"] if field["name"] == "JiraIssueId"][0]' | sed -e 's/"//g'); # Do whatever you want with the $jiraIssueId here
There are some obvious downsides to this approach, but I think it should work for now.
Related Content
- 2 years ago
- 10 years ago
- 3 years ago
Recent Discussions
- 3 months ago