使用 Powershell 从 JIRA Rest API 解析问题密钥
Parse Issue Key from JIRA Rest API using Powershell
我正在使用 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
是已发布数据变量。
使用上面的代码,您可以从 JIRA Rest API.
的 JSON 数据中获取 Issue Key 字段
对于powershell问题,如果您在服务器上安装了3.0或更高版本,您有几种方法可以替换json转换函数。
- 注册并部署以下集成包:
http://orchestrator.codeplex.com/releases/view/76101
- 在 运行 .NET 脚本 activity 的 Powershell 脚本块中执行 powershell:
https://automys.com/library/asset/powershell-system-center-orchestrator-practice-template
我不明白为什么您需要遍历键并存储键的当前索引的基于 1 的值。鉴于以上关于 powershell 的内容,以下内容将为您提供与所显示的相同的结果。在你使用它们的地方,$key 数组需要考虑元素的当前索引是从零开始的:
$results = ConvertFrom-Json $JSON
$key = $results.issues | Where-Object {$_.key -ne $null}
我正在使用 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
是已发布数据变量。
使用上面的代码,您可以从 JIRA Rest API.
的 JSON 数据中获取 Issue Key 字段对于powershell问题,如果您在服务器上安装了3.0或更高版本,您有几种方法可以替换json转换函数。
- 注册并部署以下集成包: http://orchestrator.codeplex.com/releases/view/76101
- 在 运行 .NET 脚本 activity 的 Powershell 脚本块中执行 powershell: https://automys.com/library/asset/powershell-system-center-orchestrator-practice-template
我不明白为什么您需要遍历键并存储键的当前索引的基于 1 的值。鉴于以上关于 powershell 的内容,以下内容将为您提供与所显示的相同的结果。在你使用它们的地方,$key 数组需要考虑元素的当前索引是从零开始的:
$results = ConvertFrom-Json $JSON
$key = $results.issues | Where-Object {$_.key -ne $null}