PowerShell调用jira rest api实现jira统计自动化

简介: 通过调用JIRA Rest web api实现统计自动化,首先进行登录模拟: $content = @{username='用户名';password='密码'} $JSON=$content|convertto-JSON -Compress $res = Invoke-WebReques...

通过调用JIRA Rest web api实现统计自动化,首先进行登录模拟:

$content = @{username='用户名';password='密码'}
$JSON=$content|convertto-JSON -Compress
$res = Invoke-WebRequest -Uri "http://jira地址/rest/auth/1/session" -Method Post -Body $JSON -ContentType application/json
$webClient = new-object net.webclient
#Set encoding style here.
$webClient.Encoding=[System.Text.Encoding]::GetEncoding("utf-8")
<# Note that the response contains the Set-Cookie HTTP headers that must be honoured by the caller. If you are using a cookie-aware HTTP client then it will handle all Set-Cookie headers automatically. This is important because setting the JSESSIONID cookie alone may not be sufficient for the authentication to work. #> $webClient.Headers.add("Cookie", $res.Headers["Set-Cookie"]) #Write-Host "调用获取登录状态接口" -ForegroundColor Green #$webClient.DownloadString("http://jira地址/rest/auth/1/session") #Write-Host "调用退出登录接口" -ForegroundColor Green #$webClient.UploadString("http://jira地址/rest/auth/1/session","DELETE","") #Write-Host "调用获取登录状态接口" -ForegroundColor Green #$webClient.DownloadString("http://jira地址/rest/auth/1/session")

然后查询所有分派给我的任务,并遍历每个任务取出想要的信息(例如:报告人、开发、前端、Jira创建时间等信息):

$jiraUri = "jira地址"
#查询所有分派给天外归云的任务
#Search using search request.通过查找接口用jql语句来进行查找(首先要创建一个JSON对象做为查找时post的body)
#在PowerShell中创建JSON对象.
$JSON = @"
{
    "jql": "分派给 = 天外归云",
    "startAt": 0,
    "maxResults": 1000,
    "fields": [
        "summary",
        "status",
        "assignee"
    ]
}
"@
$apiUri = "/rest/api/2/search"
$uri = $jiraUri+$apiUri
#Post json必须加的header.
$webClient.Headers.Add("Content-Type", "application/json");
$searchResult = $webClient.UploadString($uri,$JSON)
#获取所有的issues(分派给天外归云的)
$issues = ($searchResult|ConvertFrom-Json).issues
#判断有没有这种field
function NullOrNot($field){
    if(($field -ne $null) -and ($field -ne ""))
    {
       $field
    }else{
        $field="displayName : Null"
    }
}
#提取人员名单
function GetDisplayName($oName){
    $displayNames = $oName|findstr "displayName"
    if($displayNames.count -ne 1){
        foreach($displayName in $displayNames){
            $newDisplayName += $displayName.split(":")[1]
            $newDisplayName += " "
        }
        $newDisplayName
    }else{
        $displayNames.split(":")[1]
    }
}
#遍历jira issue
foreach($issue in $issues){
    $apiUri = $jiraUri+"/rest/api/2/issue/"+$issue.key
    $issueInfo = $webClient.DownloadString($apiUri)
    $issueInfo = $issueInfo|ConvertFrom-Json
    #$issueInfo.fields
    $reporter = GetDisplayName(NullOrNot($issueInfo.fields.reporter))
    Write-Host "报告人:"$reporter
    $productor = GetDisplayName(NullOrNot($issueInfo.fields.customfield_10206))
    Write-Host "产品人员:"$productor
    $qianDuan = GetDisplayName(NullOrNot($issueInfo.fields.customfield_10207))
    Write-Host "前端:"$qianDuan
    $developer = GetDisplayName(NullOrNot($issueInfo.fields.customfield_10208))
    Write-Host "开发:"$developer
    $fenPai = GetDisplayName(NullOrNot($issueInfo.fields.customfield_10002))
    Write-Host "分派给:"$fenPai
    $tiCeTime = $issueInfo.fields.created
    Write-Host "提测时间:"$tiCeTime
    Write-Host "用例数据:"$issueInfo.fields.customfield_11402 $issueInfo.fields.customfield_10400
    Write-Host "bug数:"$issueInfo.fields.customfield_10202
    Read-Host
}

以上过程中也包含了PowerShell应用于web接口测试的核心方法!

相关文章
|
存储 运维 监控
API明细日志及运维统计日志全面提升API可运维性
在数字化转型的大潮中,数据已成为企业最宝贵的资产之一。而数据服务API可快速为数据应用提供数据接口。面对越来越多的API以及越来越多的应用调用,如何快速查看API的服务情况、异常情况及影响范围,以及查看API的调用详情,进行API的性能优化、错误排查变得越来越重要,本文将介绍如何配置和开通API运维统计及明细日志,以及如何查看日志进行介绍。
675 0
|
API
LangChain-19 TokenUsage 通过回调函数 只需一行 统计当前调用API的花费情况 包含Tokens数量和Cost花费
LangChain-19 TokenUsage 通过回调函数 只需一行 统计当前调用API的花费情况 包含Tokens数量和Cost花费
236 3
LangChain-19 TokenUsage 通过回调函数 只需一行 统计当前调用API的花费情况 包含Tokens数量和Cost花费
|
缓存 API 网络架构
掌握现代API开发:GraphQL vs REST
【10月更文挑战第24天】本文深入探讨了现代API开发中两种主流技术——GraphQL和REST的设计理念、技术特点及实际开发中的对比分析。GraphQL通过声明式数据请求和强类型系统提供更高的灵活性和性能,而REST则以其无状态特性和成熟的生态系统见长。文章还讨论了两者在客户端-服务器交互、安全性和工具支持方面的优劣,帮助开发者根据项目需求做出明智选择。
|
JSON 中间件 API
开发REST API3-11
开发REST API3-11
|
JSON JavaScript API
编写REST API
编写REST API
247 2
|
监控 网络协议 安全
员工网络监控软件:PowerShell 在网络监控自动化中的应用
在数字化办公环境中,企业对员工网络活动的监控需求日益增长。PowerShell 作为一种强大的脚本语言,能够有效实现员工网络监控自动化。本文介绍了如何使用 PowerShell 获取网络连接信息、监控特定网址的访问情况,并生成自动化报告,帮助企业高效管理员工网络活动,确保网络安全和合规性。
357 0
|
监控 关系型数据库 MySQL
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
598 0
|
Java API Maven
使用 Smart-doc 记录 Spring REST API
使用 Smart-doc 记录 Spring REST API
474 0
|
XML 安全 API
REST 和 SOAP API 有什么区别?
【8月更文挑战第31天】
1047 0