Hello,
I am trying to get a list of issues from my project and sort it that way so it will be in alphabetic orded. Right now the results are displayed like this:
"AP-4 Pokemon charmander"
"AP-3 Stomp charmander"
"AP-2 Magic Bulbasaur"
"AP-1 TestingShmesting Squirtle"
The components are the pokemon names and I want to sort by using them in an alphabetical order.
This is what I am currently using:
curl -u user:password -X GET -H "Content-Type: application/json" https://examp;e.atlassian.net/rest/api/2/search\?jql\=status%20in%20\(DONE\) | jq '.issues[]| "\(.key) \(.fields.summary) \(.fields.components[].name)"'
Hi @Steven Cols,
I understand that you are wanting to return issues from Jira via the REST API, but that you want to sort these based upon a component value in each issue using the jq utility.
I'm not familiar with this jq utility you mentioned, but I downloaded this and it seems like it could be useful for parsing through json here. Your statement can work, but you should be aware that for Jira issues that have more than one value for component, they will appear in these jq filtered results once for each component they have. Which would make it look like there are duplicates here.
At first I though that your question was in regards to using Jira's native JQL, and not this jq utility itself. In which case I was just going to suggest that your Jira JQL in order to choose the order in which these issues are returned.
But there is a potential problem with trying to do this. Fields in Jira such as Components as well as Labels, are not simply a single value field. Instead these fields are arrays. This means that any issue in Jira could potentially have a nearly limitless number of component values or label values for that issue. In turn we can use JQL to filter based on the contents of that field, BUT we can't choose just a single value in that field to sort on. Instead the JQL sort will do so based on all the values in the array field.
You could alter your JQL search to look something more like this:
status=DONE ORDER BY component ASC
And if each issue only had a single component, then Jira could simply return these to you directly in the desired order. But for issues without any component, or for issues with more than one component, you will likely find that these have the potential to get ordered in an unexpected way because of the multiple values or lack of any values in that field.
Sorry this might not be the exact solution you are looking for. I understand you are asking how to do this with that jq tool, and instead I am offering a JQL work-around instead. I have been playing with jq to try to make it output these as desired, but I have to admit that I'm struggling to get the syntax just right here.
I hope this helps.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.