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的通信方式是半 ...
随机推荐
- JAVA开发Web Service几种框架介绍
郑重声明:此文为转载来的,出处已不知了,侵告删. 在讲Web Service开发服务时,需要介绍一个目前开发Web Service的几个框架,分别为Axis,axis2,Xfire,CXF以及JWS( ...
- Python学习总结15:时间模块datetime & time & calendar (二)
二 .datetime模块 1. datetime中常量 1)datetime.MINYEAR,表示datetime所能表示的最小年份,MINYEAR = 1. 2)datetime.MAXYEAR ...
- C++之路进阶——bzoj1455(罗马游戏)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser gryz2016 Logout 捐赠本站 Notice:由于本OJ ...
- 简单常用的sql,统计语句,陆续整理添加吧
1. 分段统计分数 if object_id('[score]') is not null drop table [score] go create table [score]([学号] i ...
- 实验一 操作系统模仿cmd
实验一.命令解释程序的编写 专业:商软(2)班 姓名:王俊杰 学号:201406114252 一. 实验目的 (1)掌握命令解释程序的原理: (2)掌握简单的DOS调用方法: (3 ...
- CSS3 filter:drop-shadow滤镜与box-shadow区别应用 抄的
CSS3 filter:drop-shadow滤镜与box-shadow区别应用 这篇文章发布于 2016年05月18日,星期三,01:07,归类于 css相关. 阅读 5777 次, 今日 12 次 ...
- JFreeChart在制作折线图
JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...
- 锋利的JQuery(二)
释义: DOM:Document Object Model 文档对象模型 DOM操作细分:DOM Core .HTML-DOM.CSS-DOM text():对HTML文档和XML文档都有效
- Spark实战1:shell+独立App使用总结
Spark改进了Hadoop执行非流式算法的需要多次IO的缺陷,Spark的所有操作都是基于RDD弹性分布式数据集这种数据结构的,对RDD的操作主要的操作包括transform和action两种操作. ...
- win7 chm 打开失败记录
近期学习rails,制作的html帮助文件想生成chm文件,用了几个网上的html制作chm软件,生成的chm无法打开. 网上大部分解决方法是修改文件属性,Unlock之后可解决. 以前遇到过打不开, ...