jira-cli icon indicating copy to clipboard operation
jira-cli copied to clipboard

How to set security level?

Open klaudiusz223 opened this issue 1 year ago • 7 comments

@ankitpokhrel Thanks for great software. I would like to set security level. Is it possible to set it using custom fields? When I run command

curl --request GET \
  -H "Authorization: Bearer $JIRA_API_TOKEN" \
  --url 'https://jira.examplecompany.com/rest/api/2/issue/createmeta?projectKeys=EXP&issuetypeNames=Task&expand=projects.issuetypes.fields'

I've got this answer

{
   "expand":"projects",
   "projects":[
      {
         "expand":"issuetypes",
         "self":"https://jira.examplecompany.com/rest/api/2/project/18800",
         "id":"18800",
         "key":"EXP",
         "name":"Example Module Name",
         "avatarUrls":{
            "48x48":"https://jira.examplecompany.com/secure/projectavatar?avatarId=15503",
            "24x24":"https://jira.examplecompany.com/secure/projectavatar?size=small&avatarId=15503",
            "16x16":"https://jira.examplecompany.com/secure/projectavatar?size=xsmall&avatarId=15503",
            "32x32":"https://jira.examplecompany.com/secure/projectavatar?size=medium&avatarId=15503"
         },
         "issuetypes":[
            {
               "self":"https://jira.examplecompany.com/rest/api/2/issuetype/3",
               "id":"3",
               "description":"A task.",
               "iconUrl":"https://jira.examplecompany.com/secure/viewavatar?size=xsmall&avatarId=13218&avatarType=issuetype",
               "name":"Task",
               "subtask":false,
               "expand":"fields",
               "fields":{


                  "security":{
                     "required":true,
                     "schema":{
                        "type":"securitylevel",
                        "system":"security"
                     },
                     "name":"Security Level",
                     "fieldId":"security",
                     "hasDefaultValue":true,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/securitylevel/10600",
                           "id":"10600",
                           "description":"",
                           "name":"Level 1"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/securitylevel/10801",
                           "id":"10801",
                           "description":"",
                           "name":"Level 2"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/securitylevel/10900",
                           "id":"10900",
                           "description":"",
                           "name":"Level 3"
                        }
                     ],
                     "defaultValue":{
                        "id":"10701",
                        "name":"Default",
                        "description":"Only internal users",
                        "schemeId":10100
                     }
                  },



                  "components":{
                     "required":false,
                     "schema":{
                        "type":"array",
                        "items":"component",
                        "system":"components"
                     },
                     "name":"Component/s",
                     "fieldId":"components",
                     "hasDefaultValue":false,
                     "operations":[
                        "add",
                        "set",
                        "remove"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/component/21201",
                           "id":"21201",
                           "name":"Component 1"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/component/21214",
                           "id":"21214",
                           "name":"review"
                        }
                     ]
                  },
                  "customfield_12405":{
                     "required":false,
                     "schema":{
                        "type":"option",
                        "custom":"com.atlassian.jira.plugin.system.customfieldtypes:select",
                        "customId":12405
                     },
                     "name":"Requirement Type",
                     "fieldId":"customfield_12405",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/11500",
                           "value":"Business",
                           "id":"11500",
                           "disabled":false
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/11501",
                           "value":"Operational",
                           "id":"11501",
                           "disabled":false
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/11502",
                           "value":"Compliance",
                           "id":"11502",
                           "disabled":false
                        }
                     ]
                  },
                  "issuetype":{
                     "required":true,
                     "schema":{
                        "type":"issuetype",
                        "system":"issuetype"
                     },
                     "name":"Issue Type",
                     "fieldId":"issuetype",
                     "hasDefaultValue":false,
                     "operations":[
                        
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/issuetype/3",
                           "id":"3",
                           "description":"A task",
                           "iconUrl":"https://jira.examplecompany.com/secure/viewavatar?size=xsmall&avatarId=13218&avatarType=issuetype",
                           "name":"Task",
                           "subtask":false,
                           "avatarId":13218
                        }
                     ]
                  },
                  "priority":{
                     "required":false,
                     "schema":{
                        "type":"priority",
                        "system":"priority"
                     },
                     "name":"Priority",
                     "fieldId":"priority",
                     "hasDefaultValue":true,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/priority/1",
                           "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/blocker.svg",
                           "name":"Blocker",
                           "id":"1"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/priority/2",
                           "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/critical.svg",
                           "name":"Critical",
                           "id":"2"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/priority/4",
                           "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/minor.svg",
                           "name":"Minor",
                           "id":"4"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/priority/3",
                           "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/major.svg",
                           "name":"Major",
                           "id":"3"
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/priority/5",
                           "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/trivial.svg",
                           "name":"Trivial",
                           "id":"5"
                        }
                     ],
                     "defaultValue":{
                        "self":"https://jira.examplecompany.com/rest/api/2/priority/4",
                        "iconUrl":"https://jira.examplecompany.com/images/icons/priorities/minor.svg",
                        "name":"Minor",
                        "id":"4"
                     }
                  },
                  "summary":{
                     "required":true,
                     "schema":{
                        "type":"string",
                        "system":"summary"
                     },
                     "name":"Summary",
                     "fieldId":"summary",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ]
                  },
                  "customfield_12913":{
                     "required":true,
                     "schema":{
                        "type":"option",
                        "custom":"com.atlassian.jira.plugin.system.customfieldtypes:select",
                        "customId":12913
                     },
                     "name":"Country",
                     "fieldId":"customfield_12913",
                     "hasDefaultValue":true,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18700",
                           "value":"ALL",
                           "id":"18700",
                           "disabled":false
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18603",
                           "value":"UK",
                           "id":"18603",
                           "disabled":false
                        }
                     ],
                     "defaultValue":{
                        "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18700",
                        "value":"ALL",
                        "id":"18700",
                        "disabled":false
                     }
                  },
                  "customfield_10101":{
                     "required":false,
                     "schema":{
                        "type":"any",
                        "custom":"com.pyxis.greenhopper.jira:gh-epic-link",
                        "customId":10101
                     },
                     "name":"Epic Link",
                     "fieldId":"customfield_10101",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ]
                  },
                  "description":{
                     "required":false,
                     "schema":{
                        "type":"string",
                        "system":"description"
                     },
                     "name":"Description",
                     "fieldId":"description",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ]
                  },
                  "timetracking":{
                     "required":false,
                     "schema":{
                        "type":"timetracking",
                        "system":"timetracking"
                     },
                     "name":"Time Tracking",
                     "fieldId":"timetracking",
                     "hasDefaultValue":false,
                     "operations":[
                        "set",
                        "edit"
                     ]
                  },
                  "attachment":{
                     "required":false,
                     "schema":{
                        "type":"array",
                        "items":"attachment",
                        "system":"attachment"
                     },
                     "name":"Attachment",
                     "fieldId":"attachment",
                     "hasDefaultValue":false,
                     "operations":[
                        
                     ]
                  },
                  "issuelinks":{
                     "required":false,
                     "schema":{
                        "type":"array",
                        "items":"issuelinks",
                        "system":"issuelinks"
                     },
                     "name":"Linked Issues",
                     "fieldId":"issuelinks",
                     "autoCompleteUrl":"https://jira.examplecompany.com/rest/api/2/issue/picker?currentProjectId=&showSubTaskParent=true&showSubTasks=true&currentIssueKey=null&query=",
                     "hasDefaultValue":false,
                     "operations":[
                        "add"
                     ]
                  },
                  "reporter":{
                     "required":true,
                     "schema":{
                        "type":"user",
                        "system":"reporter"
                     },
                     "name":"Reporter",
                     "fieldId":"reporter",
                     "autoCompleteUrl":"https://jira.examplecompany.com/rest/api/latest/user/search?username=",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ]
                  },
                  "customfield_16800":{
                     "required":true,
                     "schema":{
                        "type":"option",
                        "custom":"com.atlassian.jira.plugin.system.customfieldtypes:select",
                        "customId":16800
                     },
                     "name":"EXP functional",
                     "fieldId":"customfield_16800",
                     "hasDefaultValue":true,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18012",
                           "value":"Func1",
                           "id":"18012",
                           "disabled":false
                        },
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18016",
                           "value":"Others",
                           "id":"18016",
                           "disabled":false
                        },

                     ],
                     "defaultValue":{
                        "self":"https://jira.examplecompany.com/rest/api/2/customFieldOption/18016",
                        "value":"Others",
                        "id":"18016",
                        "disabled":false
                     }
                  },
                  "project":{
                     "required":true,
                     "schema":{
                        "type":"project",
                        "system":"project"
                     },
                     "name":"Project",
                     "fieldId":"project",
                     "hasDefaultValue":false,
                     "operations":[
                        "set"
                     ],
                     "allowedValues":[
                        {
                           "self":"https://jira.examplecompany.com/rest/api/2/project/18800",
                           "id":"18800",
                           "key":"EXP",
                           "name":"Example Module Name",
                           "projectTypeKey":"software",
                           "avatarUrls":{
                              "48x48":"https://jira.examplecompany.com/secure/projectavatar?avatarId=15503",
                              "24x24":"https://jira.examplecompany.com/secure/projectavatar?size=small&avatarId=15503",
                              "16x16":"https://jira.examplecompany.com/secure/projectavatar?size=xsmall&avatarId=15503",
                              "32x32":"https://jira.examplecompany.com/secure/projectavatar?size=medium&avatarId=15503"
                           },
                           "projectCategory":{
                              "self":"https://jira.examplecompany.com/rest/api/2/projectCategory/10005",
                              "id":"10005",
                              "description":"Description Category",
                              "name":"Category Name"
                           }
                        }
                     ]
                  }
               }
            }
         ]
      }
   ]
}

I have successfully run init jira but there is no "security" field in my config file. Should I add it manually? I don't know how to add such type of field. Any hint will be appreciated.

klaudiusz223 avatar Jul 14 '22 21:07 klaudiusz223

Hi @klaudiusz223, security field is not a custom field as per your config and setting this field is not directly supported. However, you can try to update the config file manually to see if it works.

- name: Security
  key: security
  schema:
    datatype: array
    items: json

# jira issue create --custom security="Level 1"

Note that you need to provide correct datatype in schema, it should be json array I think.

ankitpokhrel avatar Jul 16 '22 15:07 ankitpokhrel

Hi @ankitpokhrel Thank You for the answer. I have not tried to set the security field yet because in my case it can create a ticket with the default secuirty level, which means that I will not be able to access it. Unfortunately, I have no influence on it. I don't have administrator privileges in JIRA. Besides, I read somewhere that setting security level is not possible when creating a ticket by REST API, but it can be changed after creation. If this is the case, it means that in my case it will not work for the reasons I wrote above.

But it turned out that I am forced to set different customfield and unfortunately without success. my setup is

            - name: functional
              key: customfield_11111
              schema:
                datatype: array
              items: json

the correct request has the form (succeeded using curl)

        "customfield_11111": [
            {
                "id": "20009"
            },
            {
                "id": "20010"
            }
        ],

If I run using parameters --custom functional = {"id": "20009"}, {"id": "20010"} it is transformed in body to "customfield_11111": ["{id: 20009}", "{id: 20010}"] and should be "customfield_11111": [{"id": "20009"}, {"id": "20010"}]

I tried several ways, quoting \ using ', but with no success. e.g.

 --custom functional = {id: 20009}, {id: 20010}
--custom functional = {"id": "20009"}, {"id": "20010"}
--custom functional={\"id\":"20009"},{"id":"20010"}
--custom functional='{"id":"20009"},{"id":"20010"}'
--custom functional='{'id':"20009"},{"id":"20010"}'

I'm not sure if this is a bug or I do something wrong

klaudiusz223 avatar Jul 26 '22 21:07 klaudiusz223

I'm also unable to set custom fields, I am failing to get the example story-points working. I've tried both the name and customfield_ formats as the reference

rhysjtevans avatar Aug 08 '22 18:08 rhysjtevans

I also am unable to set story points.

It is present as an available createmeta field:

curl -k --request GET \
  --url "${JIRA_SERVER?}/rest/api/2/issue/createmeta?projectKeys=PE&expand=projects.issuetypes.fields" \
  --user "<user>:${JIRA_API_TOKEN?}"

output contains:

"customfield_10006":{"required":false,"schema":{"type":"number","custom":"com.atlassian.jira.plugin.system.customfieldtypes:float","customId":10006},"name":"Story Points","fieldId":"customfield_10006","hasDefaultValue":false,"operations":["set"]}

I have added the following to my .config/.jira/.config.yml file:

  fields:
    custom:
    - name: Story Points
      key: customfield_10006
      schema:
        datatype: number

However, none of these has an effect on ISSUE-123 (even though visiting ISSUE-123 via Web UI does allow me to edit the custom "Story Points" field):

jira issue edit ISSUE-123 --custom=story-points=1 --no-input
jira issue edit ISSUE-123 --custom story-points=2 --no-input
jira issue edit ISSUE-123 --custom "story points"=3 --no-input
jira issue edit ISSUE-123 --custom "Story Points"=4 --no-input
jira issue edit ISSUE-123 --custom="Story Points"=3 --no-input --debug
jira issue edit ISSUE-123 --custom=customfield_10006=4 --no-input --debug

I can see the following output in the terminal:

✓ Issue updated
JIRA_SERVER/browse/ISSUE-123

However, the story point in ISSUE-123 remain unchanged.

MattPD avatar Sep 08 '22 22:09 MattPD

Just checked on Jira v8.22.1 and it seem to be working fine in my installation.

@MattPD your config looks ok to me, could you please mention what version of jira you are using? You can get it with jira serverinfo if you are using the latest version of jira-cli.

@rhysjtevans Any additional details to help debug the issue would be great (eg: is this happening for just story points custom field or others too?).

ankitpokhrel avatar Sep 09 '22 07:09 ankitpokhrel

Interesting--I do have the latest release but it doesn't appear to be recognized:

$ jira serverinfo
Error: unknown command "serverinfo" for "jira"
Run 'jira --help' for usage.
unknown command "serverinfo" for "jira"

$ jira version
(Version="1.1.0", GitCommit="3b93e147eac468ad985bdece27469153b4bb2814", CommitDate="2022-08-14T08:10:40+00:00", GoVersion="go1.18.3", Compiler="gc", Platform="linux/arm64")

I can wait for the next release if this requires the latest commit build--or perhaps there's some way I can check this via Curl?

FWIW, the bottom of my Jira Web UI says "Atlassian Jira Project Management Software (v8.20.5#820005" and visiting the AboutPage.jspa shows

Jira v8.20.5
Copyright © 2002 - 2022 Atlassian Corporation Pty Ltd.

MattPD avatar Sep 12 '22 22:09 MattPD

Hi @MattPD, serverinfo command is not yet released, my bad. I checked this on Jira v8.20.5 and the story points is updated successfully in my installation.

It would be helpful if someone can debug this a bit and provide more info.

ankitpokhrel avatar Oct 08 '22 18:10 ankitpokhrel