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的通信方式是半 ...
随机推荐
- Lintcode: Flip Bits
Determine the number of bits required to flip if you want to convert integer n to integer m. Have yo ...
- DataBase: MySQL在.NET中的应用
首先需要下载MySQL: 1. 官方下载 dev.mysql.com/downloads/mysql/ 2. 解压到你所想要安装的位置,在文件夹里创建my.ini文件 [mysql] # 设置mysq ...
- UML: 序列图
摘自http://www.umlonline.org/school/thread-37-1-1.html 大家都进过餐馆吃饭吧?你是如何和餐厅服务员“眉来眼去”的呢?回忆一下从你进餐馆开始到你离开餐馆 ...
- javascript语法详解
javascript语法:运算符 条件语句if...else... 条件语句switch 循环语句for 循环语句while 跳转语句 js运算符 1.算数运算符:+ - * % / ++ ...
- Oracle的分页查询
--1:无ORDER BY排序的写法.(效率最高)--(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!) SELECT * FROM (SELECT ...
- 使用 nano 的时候提示找不到 libncursesw.so.5 这个共享库
由于拿nano来练习pacman这个包管理系统,也就是卸了装,装了卸.但是后来当我想用 nano 编辑文件的时候,系统提示标题上说的这错误. 不知道做了什么,难道是误删了什么东西...后来几番搜索,用 ...
- ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误)
在ASP.NET MVC4中微软引入了bundles特性,这个特性可以将服务器端的多个Javascript或多个css文件捆绑在一起作为一个单一的URL地址供客户端浏览器调用,从而减少了页面上Http ...
- java类的访问权限
1.解析 Java有四种访问权限, 其中三种有访问权限修饰符,分别为private,public和protected,还有一种不带任何修饰符. private: Java语言中对访问权限限制的最窄的修 ...
- 《REWORK》启示录 发出你的心声——程序员与身体
Sound Like You 所谓的标题在这里并不是为了吸引眼球,不过也是为了吸引眼球,只是出发点已经不一样了.这是一篇适合给程序员看的关于健康的文章,也许你认识李开复也可以给他看看,上过养生过,觉得 ...
- 如何在视频处理控件TVideoGrabber中设置音频捕捉设备
TVideoGrabber不仅可以捕捉视频,还可以作为多媒体播放器,并支持包括C#..NET.VB.NET.C++.Delphi.C++Builder和ActiveX平台,本文将剖析TVideoGra ...