Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation list doesn't work

Kawtar Amajoud February 1, 2024

So I send a webrequest, get the webResponse.body which I'll call List A and save it in VariableA. I do this again with a second webrequest and save List B in VariableB.

Next I create variableC with:

{{variableA}},{{variableB}}

(I've tried with a space after the comma and without)

Next I try to use variableC. Printing the variable works, however doing anything else with it doesn't.

So logging:

{{variableC}}

works and shows a neat list.

However if I were to do:

{{variableC.first}}

or

{{#variableC}}Release name: {{name}}. {{/}}

it does not work and prints nothing, I've tried countless things but absolutely nothing works.

The data itself looks like the below, these are 2 items of many:

{self=https://company.atlassian.net/rest/api/3/version/10371, id=10371, description=Release of the 4th week of 2024, name=RWK24_04, archived=false, released=true, releaseDate=2024-01-24, userReleaseDate=24/Jan/24, projectId=10021}, {self=https://company.atlassian.net/rest/api/3/version/10367, id=10367, description=First release of 2024, name=RWK24_02, archived=false, released=true, releaseDate=2024-01-11, userReleaseDate=11/Jan/24, projectId=10021}

 

EDIT: For more details please see my reply to Kalyan.

2 answers

1 vote
Kalyan Sattaluri
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024

Jira Variables store your list values as just text.

So you cannot do .first in your variable directly.

You need to do  {{variableC.split(", ")}} to convert to a list first I believe...

 

Also, I see you are making  a call to the project versions end point, what are you trying to do? Can you clarify?

Kawtar Amajoud February 2, 2024

Splitting on a comma doesn't work, please see the data sample. Those are 2 objects which use comma's internally as well. Splitting with a curly bracket causes errors.

Of project A, B and C in Jira I want to do the following tasks:

  1. get all versions from project A, B and C
  2. get all version id's of which the name matches X

  3. get all tickets of those versions

  4. Display the list in confluence

My problem is with task 2 as the lists form task 1 are unusable. (3 and 4 are successful).

The Web request for 1 is:

https://company.atlassian.net/rest/api/3/project/A/versions
https://company.atlassian.net/rest/api/3/project/B/versions
etc.

I save the

{{webResponse.body}} 

in separate variables (listA, listB etc.)

These lists also don't work, even before they are combined into 1.

{{listA.first}}

returns nothing. The full list prints fine though :(

--> If I use the last webResponse directly I can use the list to do whatever. But the moment it is saved in a variable it becomes unusable. How can I save it in a usable way? I've tried all kinds of things and encodings but nothing.

In the documentation it says I can use past webResponses by doing something like:

{{webResponse.getFromEnd(1).body}}

But that doesn't work either... :(

The only thing that seems to work is directly using the last {{webResponse.body}}.

Please help!

 

 

If curious see below but it's not necessary for the issue.

Task 2 details

I want to filter the list, like this

A. create a variable called filteredVersions with value empty,

B. create the same variable with

{{filteredVersions.remove("empty")}}

I then have an empty variable to use.

C. Create it again for task 2 and do something like this:

{{#listA}}
{{#if(body.name.equals("Name_X"))}}
{{filteredVersions.concat(id)}}
{{/}}
{{/}}

But C doesn't work for the above reason that nothing can be done with the list. Not sure if there are more issues with this, but I can't get any further (or debug) without being able to use the list from task 1.

 

Task 3

In case you're curious, the webrequest for task 3 is the below (no issues):

https://company.atlassian.net/rest/api/3/search?jql={{A}}&maxResults=1000

On the spot of {{A}}, I'd want to use the list of filtered version id's from task 2 like:

{{#list}}fixVersion={{id}}{{^last}}%20or%20{{/}}{{/}}

The response with x amount of tickets, I'm going to display in a table on confluence. This part has been tested and works.

 

 

Kalyan Sattaluri
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2024

@Kawtar Amajoud  I am still confused.

 

First, If your final goal is to display the list in confluence, why are you not using JQL directly, why are you making web requests in automation. Have you tried to do this search directly in JQL? I am pretty sure you can do this directly in JQL and even if you want to use automation route for some reason, you can skip calls to get versions and use the JQL directly in your search end point.

So what is your requirement in the end? You say you want to "match" a fix version name but also you are looking for exact value? Please clarify.

 

Second, As mentioned, when you store web response in listA, listA containt text. so you cannot do listA.first. It is not a list...

 

Finally, just as a thought experiment,  

  • If you are looking at exact match of a fix version name, say Name_X, make a call to Project A's version, capture below value in variable varA.

{{#webhookResponse.body}} {{#if(equals(name,"Name_X"))}} {{id}} {{/}} {{/}}

  • Do same for Project B in varB.

Your end JQL for search will be something like

/rest/api/3/search?jql=fixVersion={{varA}}%20or%20fixVersion={{varB}}

If you need to match, you need to modify above logic differently.

 

Still I am confused why automation and not pull this list directly in confluence using Jira macro and JQL so please clarify that first..

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024

Hi @Kawtar Amajoud -- Welcome to the Atlassian Community!

What problem are you trying to solve by merging the results of the two REST API calls?  Knowing that may help the community to offer better suggestions.

 

Until we know that...

Created variables are text, and when the web response is stored it loses all name attributes and typing information.  And so concatenating the values just produces a longer text string. 

The text string could be split back into a lists, using the split() function: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#split-String-separator-

Or, the name attributes can be preserved by instead storing the web responses in lookup tables: https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Create-lookup-table

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events