PowerShell调用jira rest api实现jira统计自动化
通过调用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接口测试的核心方法!
PowerShell调用jira rest api实现jira统计自动化的更多相关文章
- PowerShell调用jira rest api实现对个人提交bug数的统计
通过PowerShell的invoke-webrequest和net.client联合实现个人指定项目jira提交数的统计,其中涉及到了JSON对象的提交,代码如下: $content = @{use ...
- 获取使用GitHub api和Jira api Authentication的方法
近段时间在搭建我司的用例管理平台,有如下需求: 1.需要根据项目--版本--轮次的形式来管理项目用例,用例统一保存在git工程. 2.执行用例时,如果用例执行失败,可以通过平台在Jira上提bug. ...
- 【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)
问题描述 PowerShell 脚本调用Azure REST API, 但是所有的API都需要进行权限验证.要在请求的Header部分带上Authorization参数,并用来对List Resour ...
- Python3调用Hadoop的API
前言: 上一篇文章 我学习使用pandas进行简单的数据分析,但是各位...... Pandas处理.分析不了TB级别数据的大数据,于是再看看Hadoop. 另附上人心不足蛇吞象 对故事一的感悟: ...
- 调用百度汇率api 获取各国的汇率值
设置一个定时任务,每天更新汇率java代码如下 package com.thinkgem.jeesite.modules.huiLvApi.service; import java.io.Buffer ...
- C#调用百度地图 api
转 http://blog.csdn.net/kkkkkxiaofei/article/details/8663377 这一篇,记录一下我调用的地图API实现的功能.下面介绍的都是一些片段的节选,不 ...
- 关于c#调用java中间件api的几个问题
由于项目需要,做的c#客户端数据库连接串首先肯定不能写死的程序里(数据库很容易被攻击,我们的项目半年改了几次密码...) 放置在配置文件内,都可以看得到,最开始想法将配置文件加密,老师说加密过的文件还 ...
- C#中可直接调用WIN32的API函数--USER32.DLL
Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...
- mfc 调用Windows的API函数实现同步异步串口通信(源码)
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
随机推荐
- for 穷举、迭代 while循环
1.穷举: 把所有可能的情况都走一遍,使用if条件筛选出来满足条件的情况. 2.百鸡百钱:公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一只,总共只有100文钱,如何在凑够100只鸡的情况下刚好花完100 ...
- 弦图的判定MCS算法(zoj1015)
题意:裸的弦图的判定: 弦图定义:给出一个无向连通图,如果每个环中都存在至少一条弦(环中存在不相邻的两点直接相连)这样的图叫做弦图: 转载:http://blog.csdn.net/crux_d/ar ...
- UML: 状态机图
摘自http://www.umlonline.org/school/viewthread.php?tid=39 活动图将流程分解为一个一个的活动,通过活动的先后顺序来展示流程:而状态机图从某个物品的状 ...
- ofbiz进击 个人遇到的奇葩问题汇总。
在本人做退货单生成的时候,因为考虑到要控制通过java类方法去调用 service服务可以方便给出提示消息,所以专门新建了一个java类,然后去重新请求request请求,下面为Java类的代码 pu ...
- Node.js Express 获取request原始数据
app.use(bodyParser.json());客户端请求接口时如果指名请求头类型 为Content-Type=application/jsonbodyParser 会自动将 body 里的 j ...
- AS-demo09
,mainifast: <uses-permission android:name="android.permission.SET_WALLPAPER"/> , < ...
- paper 53 :深度学习(转载)
转载来源:http://blog.csdn.net/fengbingchun/article/details/50087005 这篇文章主要是为了对深度学习(DeepLearning)有个初步了解,算 ...
- Sql Server服务远程过程调用失败解决
Sql Server服务远程过程调用失败解决 问题: 今天SQL数据库登录不上了,然后想启动Sql实例,却发现如下问题(配置环境:win7旗舰版x64,SqlServer2008R2, ...
- 【RoR win32】新建rails项目找不到script/server的解决办法
现象: D:\>rails new work/demo cd work/demo D:\work\demo>ruby script/server 这时显示出错: ruby: No such ...
- Entity Framework 无法对没有主键的视图映射实体的解决办法
我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...