You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JiraPS创建Jira工单时遇参数错误求助

解决PowerShell创建Jira工单的报错问题

问题根源分析

从报错信息和代码来看,存在两个明确问题:

  • components字段格式不符合要求:Jira API要求components参数必须为数组类型,当前传入的是单个字符串,导致验证失败。
  • customfield_10029的ID无效且格式错误:指定的id=1023不在Get-JiraIssueCreateMetadata返回的允许值列表中,同时哈希表键名未用引号包裹,格式不规范。

修正后的代码

$cred = mycredential

Set-JiraConfigServer -Server "https://myserver.atlassian.net"
Get-JiraIssue -Issue "DEV-999" -Credential $cred

Get-JiraIssueCreateMetadata -Project DEV -IssueType Task -Credential $cred | ? {$_.Required -eq $true}

# 修正components数组格式,customfield_10029使用有效ID并规范哈希表写法
$fields = @{
    'components' = @(
        @{name = 'Century Distribution Systems, Inc.'}
    )
    'customfield_10029' = @{id = '10231'} # 选用允许值中的有效ID,示例为DatabaseQueue对应的10231
}

New-JiraIssue -Project "DEV" -IssueType "Task" -Summary "Test for backup automation" -Description "Test for backup automation" -Reporter "me@here.com" -Labels "Maintenance:Refactoring" -Parent "DEV-998" -Credential $cred -Fields $fields -verbose

关键修正说明

  • components字段:用@()包裹为数组,每个组件以@{name='组件名称'}的哈希表格式传入,确保Jira能正确解析。
  • customfield_10029字段:使用Get-JiraIssueCreateMetadata返回的有效ID(如10231),并以标准哈希表@{id='xxx'}格式传递,ID值需用引号包裹为字符串类型。

内容的提问来源于stack exchange,提问作者creffner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 18:05:29