博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PowerShell调用jira rest api实现jira统计自动化
阅读量:7015 次
发布时间:2019-06-28

本文共 3188 字,大约阅读时间需要 10 分钟。

通过调用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#判断有没有这种fieldfunction 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 issueforeach($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接口测试的核心方法!

转载地址:http://vphtl.baihongyu.com/

你可能感兴趣的文章
又拍云专注场景化CDN 云CDN加速行业全面演进
查看>>
.NET仓储模式高级用例
查看>>
Netty消息接收类故障案例分析
查看>>
如何理解 Laravel 的 Ioc 容器
查看>>
如何用Uber JVM Profiler等可视化工具监控Spark应用程序?
查看>>
Checkly如何借助Terraform实现零宕机部署
查看>>
为什么已有Elasticsearch,我们还要重造实时分析引擎AresDB?
查看>>
玩大了,开源协议修改引发MongoDB“大动荡”?
查看>>
Kafka团队修改KSQL开源许可,怒怼云厂商
查看>>
腾讯云视频技术全面升级 明眸、Tencent-RTC首度亮相
查看>>
Elasticsearch 7.0中引入的新集群协调子系统如何使用?
查看>>
PostgreSQL中的大容量空间探索时间序列数据存储
查看>>
IBM借QISKit打造基于云平台的量子计算
查看>>
红帽发布 Ansible Tower 3.4:在混合云中实践DevOps更便捷
查看>>
你真的了解前端模块化吗?
查看>>
input type="search" 实现搜索框
查看>>
用PVS在.NET内核中发现的缺陷
查看>>
扎克伯格发信表示押注区块链,即时通讯 + 加密货币 = 全球化使用!
查看>>
高效 Mac 人士必备:实现工作/家庭间网络环境切换的自动化
查看>>
《Java 20年:道路与梦想》迷你书发布
查看>>