0

I have json file (1.json), i can iterate through it to find project,parent keys and custom fields

jq -r '.issues[] | .key' 1.json
jq -r '.issues[] | .fields.project.key' 1.json
jq -r '.issues[] | .fields.customfield_10107.id' 1.json

Output:

TECH-540
TECH-531
TECH-627
TECH-538
TECH-577
TECH-572
TECH-520
TECH-565
TECH-567
TECH
TECH
TECH
TECH
TECH
TECH
TECH
TECH
TECH
10400
10400
10400
10400
10400
10400
10400
10400
10400

I want to store TECH-XXX to project=jq -r '.issues[] | .key' 1.json TECH to parent=jq -r '.issues[] | .fields.project.key' 1.json 10400 to custom_field=jq -r '.issues[] | .fields.customfield_10107.id' 1.json variable for each value found in 1.json file do for loop following code (in this case run curl 9 times):

curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"$project\"},\"parent\":{\"key\":\"$parent\"},\"summary\":\"Test ChargenNr\",\"description\":\"some description\",\"issuetype\":{\"name\":\"Sub-task\"},\"customfield_10107\":{\"id\":\"$custom_field\"}}}" -H "Content-Type:application/json" https://jira.company.com/rest/api/latest/issue/

1 Answer 1

1

Ended up using nested loop

for project in `cat 1.json  | jq -r .issues[].key`; do

  for parent in `cat 1.json  | jq -r .issues[].fields.project.key`; do
     for custom_field in `cat 1.json  | jq -r .issues[].fields.customfield_10107.id`; do

      echo $i>/tmp/ja.txt

done
  done
    echo $project $parent  $custom_field
    curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"$project\"},\"parent\":{\"key\":\"$parent\"},\"    summary\":\"Test ChargenNr\",\"description\":\"some description\",\"issuetype\":{\"name\":\"Sub-task\"},\"customfield_10107\":{\"id\":\"$custom_field\"}}}" -H "Content-Type:application/json" https://jira.company.com/rest/api/latest/issue/
    done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.