AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
324 stars 131 forks source link

custom field with variable #125

Closed inlikefletch closed 7 years ago

inlikefletch commented 7 years ago

Curious how one can create an issue with declaring a fields argument when the component name is a variable. i.e.: -Fields @{'components'= @(@{name = $categoryName})}

Current Behavior

I get an error stating: Get-Member : You must specify an object for the Get-Member cmdlet.

Context

I assume there is some issue of how to declare an object in an array in an object with a variable.

Your Environment

Get-Module PSJira -ListAvailable select version Version

1.2.5.251 $PSVersionTable Name Value


PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Thanks, Jason

P.S. awesome model!

lipkau commented 7 years ago

Can you describe how you would like it to work?

inlikefletch commented 7 years ago

Yes, so in the following example, I supply a New-JiraIssue command with variables

i.e. New-JiraIssue -Project $project -IssueType $issueType -Reporter $reporter -Summary $summary -Description $description -Fields @{'components'= @(@{name = $categoryName})}

But it does not like the format of the fields attribute. If I eliminate the variable in the fields attribute, and just have a string, it works. But I would like to determine how to use a variable in the field.

i.e. New-JiraIssue -Project $project -IssueType $issueType -Reporter $reporter -Summary $summary -Description $description -Fields @{'components'= @(@{name = 'MyCategoryName'})}

inlikefletch commented 7 years ago

Okay, so I come to learn its not an issue of my code, but rather where I am running the code. The following works on my desktop, but not the server.

New-JiraIssue -Project $project -IssueType $issueType -Reporter $reporter -Summary $summary -Description $description -Fields @{'components'= @(@{name = "$components"})}

I need to do some more troubleshooting.

Thanks, Jason

inlikefletch commented 7 years ago

On my server, I see the following error. Command works fine on my desktop. Updated server to match PSVersion 5.1, still have the issue. Get-JiraIssue commands work fine on the server. Not sure why PS on my server is handling object differently or if some other module is require for PSJira.

PS C:\Users\user> New-JiraIssue -Project $project -IssueType $issueType -Reporter $reporter -Summary $summary -Description $description -Fields @{'components'= @(@{name = "$components"})} -Verbose VERBOSE: Using saved Web session with username jirauser VERBOSE: GET https://jira.xxx.xxx/rest/api/latest/project/SVCS?expand=projectKeys with 0-byte payload VERBOSE: received -1-byte response of content type application/json;charset=UTF-8 VERBOSE: Using saved Web session with username jirauser VERBOSE: GET https://jira.xxx.xxx/rest/api/latest/issuetype with 0-byte payload VERBOSE: received -1-byte response of content type application/json;charset=UTF-8 VERBOSE: Using saved Web session with username jirauser VERBOSE: GET https://jira.xxx.xxx/rest/api/latest/issue/createmeta?projectIds=11632&issuetypeIds=16&expand=projects.issuetypes.fields with 0-byte payload VERBOSE: received -1-byte response of content type application/json;charset=UTF-8 Get-Member : You must specify an object for the Get-Member cmdlet. At C:\Program Files\WindowsPowerShell\Modules\PSJira\1.2.5.251\Internal\ConvertTo-JiraCreateMetaField.ps1:37 char:32

lipkau commented 7 years ago

@inlikefletch please open the following URL in a browser in which you are already authenticated with your jira server and send me the json that is displayed:

https://jira.XXX.XXX/rest/api/latest/project/11632

inlikefletch commented 7 years ago

Hi @lipkau Thanks for the response. What are you looking to gain from that url? I am cautious to post any internal data. I understand which fields are required for my post commands. And like I mentioned, this exact command works on my desktop.

lipkau commented 7 years ago

The error you posted is due to the input to the ConvertTo-JiraCreateMetaField to be empty. Which means that the Get-JiraIssueCreatMetadata is getting no response for the issue types in the project.

The url I sent you gives the config of the project. Except for the url of your server, it contains no sensitive information

inlikefletch commented 7 years ago

@lipkau copied below:

{"expand":"description,lead,url,projectKeys","self":"https://jira.xxx.xxx/rest/api/latest/project/11632","id":"11632","key":"SVCS","description":"","lead":{"self":"https://jira.xxx.xxx/rest/api/2/user?username=cis-cs","key":"cis-cs","name":"cis-cs","avatarUrls":{"48x48":"https://jira.xxx.xxx/secure/useravatar?ownerId=cis-cs&avatarId=12535","24x24":"https://jira.xxx.xxx/secure/useravatar?size=small&ownerId=cis-cs&avatarId=12535","16x16":"https://jira.xxx.xxx/secure/useravatar?size=xsmall&ownerId=cis-cs&avatarId=12535","32x32":"https://jira.xxx.xxx/secure/useravatar?size=medium&ownerId=cis-cs&avatarId=12535"},"displayName":"CIS Enterprise Systems - Core Services","active":true},"components":[{"self":"https://jira.xxx.xxx/rest/api/2/component/14264","id":"14264","name":"Active Directory","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12469","id":"12469","name":"AD Certificate Authority","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12477","id":"12477","name":"Azure","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12478","id":"12478","name":"Citrix","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12496","id":"12496","name":"DFS","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/14055","id":"14055","name":"DHCP","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12476","id":"12476","name":"Exchange OnPrem","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13312","id":"13312","name":"listserv","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13350","id":"13350","name":"LogStash","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13303","id":"13303","name":"Operating System","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13315","id":"13315","name":"OSSec","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12855","id":"12855","name":"PRTG","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12472","id":"12472","name":"SMTP","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13314","id":"13314","name":"SQL Server","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13956","id":"13956","name":"Squid","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13159","id":"13159","name":"SSL","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/13050","id":"13050","name":"TS Gateway","isAssigneeTypeValid":false},{"self":"https://jira.xxx.xxx/rest/api/2/component/12556","id":"12556","name":"Veeam Backup","isAssigneeTypeValid":false}],"issueTypes":[{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/3","id":"3","description":"General work that needs to be done","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12748&avatarType=issuetype","name":"Task","subtask":false,"avatarId":12748},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/9","id":"9","description":"A project related to the owning product/team","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12737&avatarType=issuetype","name":"Project","subtask":false,"avatarId":12737},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/6","id":"6","description":"General work that needs to be done","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12748&avatarType=issuetype","name":"Sub-Task","subtask":true,"avatarId":12748},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/5","id":"5","description":"A system upgrade or patch","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12740&avatarType=issuetype","name":"Upgrade/Patch","subtask":false,"avatarId":12740},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/16","id":"16","description":"An problem or issue that needs attention and is not part of anticipated operations.","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=19211&avatarType=issuetype","name":"Problem","subtask":false,"avatarId":19211},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/10","id":"10","description":"A report or dashboard (Argos, Tableau, Jobsub, etc.)","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12736&avatarType=issuetype","name":"Report","subtask":false,"avatarId":12736},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/12","id":"12","description":"A report or dashboard (Argos, Tableau, Jobsub, etc.)","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12736&avatarType=issuetype","name":"Sub-Report","subtask":true,"avatarId":12736},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/10101","id":"10101","description":"A change to a system, configuration, or process","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=19235&avatarType=issuetype","name":"Sub-Change","subtask":true,"avatarId":19235},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/10100","id":"10100","description":"A change to a system, configuration, or process","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=19234&avatarType=issuetype","name":"Change","subtask":false,"avatarId":19234},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/2","id":"2","description":"A new feature or new piece of work to be done","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12741&avatarType=issuetype","name":"New Feature","subtask":false,"avatarId":12741},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/11","id":"11","description":"A new feature or new piece of work to be done.","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=12741&avatarType=issuetype","name":"Sub-New Feature","subtask":true,"avatarId":12741},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/10200","id":"10200","description":"An problem or issue that needs attention and is not part of anticipated operations","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=19331&avatarType=issuetype","name":"Sub-Problem","subtask":true,"avatarId":19331},{"self":"https://jira.xxx.xxx/rest/api/latest/issuetype/10300","id":"10300","description":"A permissions request","iconUrl":"https://jira.xxx.xxx/secure/viewavatar?size=xsmall&avatarId=14632&avatarType=issuetype","name":"Permissions","subtask":false,"avatarId":14632}],"assigneeType":"PROJECT_LEAD","versions":[],"name":"Enterprise Infrastructure Services","roles":{"Developers":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10220","Workers":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10001","Project Manager":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10010","Administrators":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10002","Users":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10000","Stakeholders":"https://jira.xxx.xxx/rest/api/latest/project/11632/role/10020"},"avatarUrls":{"48x48":"https://jira.xxx.xxx/secure/projectavatar?pid=11632&avatarId=11931","24x24":"https://jira.xxx.xxx/secure/projectavatar?size=small&pid=11632&avatarId=11931","16x16":"https://jira.xxx.xxx/secure/projectavatar?size=xsmall&pid=11632&avatarId=11931","32x32":"https://jira.xxx.xxx/secure/projectavatar?size=medium&pid=11632&avatarId=11931"},"projectCategory":{"self":"https://jira.xxx.xxx/rest/api/latest/projectCategory/10030","id":"10030","name":"Infrastructure, Hardware and Services","description":""},"projectTypeKey":"software"}

lipkau commented 7 years ago

ok. json looks fine. there must be an other reason for the problem... what is different between the desktop and the server? http proxy maybe? sure the credentials are ok?

inlikefletch commented 7 years ago

Issue resolved. Ended up being a permissions issue within jira permissions.

Thanks for helping!