How to refer to a newly created issue to perform CLI actions through scripts

When issues are created using CLI scripts, the key values are not known when the scripts are still running. In such cases, further actions cannot be performed on these issues as there is no key value that can be used. This article describes how to provide a reference to such issues using a reference key. This reference key acts as a temporary key value and is valid only in that specific script. When a reference key is used, a validation check is performed on the key before executing the next CLI action. If the validation fails, all further actions are ignored.

Refer to this link for more information about variable replacements you can use as reference keys.

Instructions

Use the --reference parameter for defining the reference key(s).

  1. To create multiple issues and add comments to some of the newly created issues, add the --reference parameter to that specific createIssue action.

    1. Create a script file with a set of commands (as required).  For this example we name the file reference.csv.

    2.  After the script is ready, run the CLI command.

      --action run --file "reference.csv"
    3. Three issues are created as a result of the CLI command. The first issue in the list is added with a comment, 'my comment', and is restricted to the 'Developers' group.

      jira --action run --file "reference.csv"
      
      Run: --action createIssue --project "ZCLI" --type "Task" --summary "reference1" --reference l1ef
      Issue ZCLI-2 created with id 10225.
      
      Run: --action createIssue --project "ZCLI" --type "Bug" --summary "test reference" --reference l2ef
      Issue ZCLI-3 created with id 10226.
      
      Run: --action createIssue --project "ZCLI" --type "Incident" --summary "comment reference" --reference l3ef
      Issue ZCLI-4 created with id 10227.
      
      
      Run: --action addComment --issue ZCLI-2 --comment "my comment" --role "Developers"
      Comment with id 10000 added to ZCLI-2.
      
      Run completed successfully. 4 actions were successful from file 'reference.csv'.

      Similarly, if you want to link issues then run the script as given below. This script creates three issues such that the first issue and the second issue are linked with the link type, 'blocks'. 

      --action createIssue --reference myFirstIssue --project ZCLI --type "Task" --summary "issue"
      --action createIssue --reference mySecondIssue --project ZCLI --type "Task" --summary "issue2"
      --action createIssue --reference myThirdIssue --project ZCLI --type "Task" --summary "issue3" 
      
      --action linkIssue --issue @myFirstIssue@ --toIssue @mySecondIssue@ --link "blocks"
  2. To create multiple issues and create subtasks under specific parent issues, add the reference column to the createIssue actions of the parent issues.

    1. Create a .csv file along with the references to the parent tickets.  Again, we'll name the file reference.csv in this example.

    2. After creating the CSV file, run the CLI command.

      --action runFromCsv --file "reference.csv"  --common "--project "ZCLI" --continue
    3.  Three parent tickets are created along with the two subtasks. The subtasks are created under the Task and Incident request based on the references given to the subtasks in the CSV file. The result is similar to the output below:

      jira --action runFromCsv --file "reference.csv"  --common "--project CLI" --continue
      
      Run: --action "createIssue" --issue "" --parent "" --type "Task" --reporter "automation" --summary "Task ticket" --reference "myreference1" --project ZCLI --continue
      Issue ZCLI-51 created with id 10230.
      
      Run: --action "createIssue" --issue "" --parent "" --type "Bug" --reporter "automation1" --summary "Bug ticket" --reference "myreference12" --project ZCLI --continue
      Issue ZCLI-52 created with id 10231.
      
      Run: --action "createIssue" --issue "" --parent "CLI-51" --type "Subtask" --reporter "automation2" --summary "subtask ticket 1" --project ZCLI --continue
      Issue CLI-53 created with id 10232 as subtask of ZCLI-51.
      
      Run: --action "createIssue" --issue "" --parent "" --type "Incident" --reporter "automation3" --summary "Incident ticket" --reference "myreference3" --project ZCLI --continue
      Issue ZCLI-54 created with id 10233
      
      Run: --action "createIssue" --issue "" --parent "ZCLI-54" --type "Subtask" --reporter "automation4" --summary "subtask ticket2" --project ZCLI --continue
      Issue ZCLI-55 created with id 10234 as subtask of ZCLI-54.
      
      Run completed successfully. 5 actions were successful from file: reference.csv
  • Use relevant naming convention. Names such as refer1, myreference1, and so on, are used as examples.
  • The variable replacements article describes how you can reference the last created issue or subtask in your script.