使用Powershell从JIRA Rest API解析问题密钥



我正在使用System Center Orchestrator和Powershell为JIRA设置一个自动化过程。在这个例子中,我已经有了来自JIRA Rest API的原始JSON数据。

function ConvertFrom-Json20([object] $item){ 
    add-type -assembly system.web.extensions
    $ps_js=new-object system.web.script.serialization.javascriptSerializer
    #The comma operator is the array construction operator in PowerShell
    return ,$ps_js.DeserializeObject($item)
}
[object]$JSON = '{Raw JSON Data from JIRA Variable}'
$results = ConvertFrom-Json20($JSON)
$key = @()
$count = @()
foreach( $issue in $results.issues ) { 
    $key += $issue.key
    $count += $key.count
}
$key = @($key | Where-Object {$_ -ne $null})
$count = @($count | Where-Object {$_ -ne $null})

我使用的服务器没有最新的Powershell包,所以这就是我包含ConvertFrom-Json20([object])功能的原因。在SCORCH中,$key$count是Published Data变量

使用上面的代码,您可以从JIRA Rest API的JSON数据中获得Issue Key字段。

对于powershell问题,如果您在服务器上安装3.0或更高版本,您有几种方法来替换json转换函数。

  1. 注册并部署以下集成包:http://orchestrator.codeplex.com/releases/view/76101
  2. 在powershell脚本块中为Run .NET script活动执行powershell:https://automys.com/library/asset/powershell-system-center-orchestrator-practice-template

我不明白为什么你需要遍历键并存储键当前索引的基于1的值。考虑到上述关于powershell的信息,下面的操作将给出与您所显示的相同的结果。在使用它们的地方,$key数组需要说明元素的当前索引为0:

$results = ConvertFrom-Json $JSON
$key = $results.issues | Where-Object {$_.key -ne $null}

最新更新