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的通信方式是半 ...
随机推荐
- 转:Jmeter之Bean shell使用(一)
一.什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法; BeanShell是一种松散类型的脚本语言(这点和JS类似); BeanS ...
- poj: 2739
挺简单,生成素数表之后建个全素数的vector,然后..随便玩咯 #include <iostream> #include <stdio.h> #include <str ...
- Spring的2个思想
IOC:控制反转 反转:获取依赖对象的方式被反转了 控制反转是关于一个对象如何获取他所依赖的对象的引用,反转是指责任的反转. (1)对象实例化问题(Spring完成) 传统的依赖方式:程序员实例化 ( ...
- 。。。HibernateTemplate与Session。。。
今天在学习Spring框架的时候,突然发现了这个类----HibernateTemplate,这个类与Session一开始认为是差不多的,这个HibernateTemplate类对象拥有Session ...
- paper 86:行人检测资源(上)综述文献【转载,以后使用】
行人检测具有极其广泛的应用:智能辅助驾驶,智能监控,行人分析以及智能机器人等领域.从2005年以来行人检测进入了一个快速的发展阶段,但是也存在很多问题还有待解决,主要还是在性能和速度方面还不能达到一个 ...
- logstash5.x改变
5.x版本 logstash中 elasticsearch插件的workers,无法配置大于1,会提示 This plugin uses the shared and doesn't need thi ...
- 夺命雷公狗—angularjs—15—内置封装好的计时器$interval和$timeout
这里其实和js源生的效果是一样的,但是源生的在angularjs里面不能直接正常执行代码如下所示: <!DOCTYPE html> <html lang="en" ...
- PTPX中的clock tree与LP design
PTPX在加入CPF/UPF这样的文件后,可以分析multi-voltage,power-gating这样的设计. 针对某个power rail的cell,PTPX支持进行annotate. set_ ...
- centos的用户管理相关命令所在的包
用户管理命令是指:useradd userdel groupadd groupdel 这些 这些命令出自一个叫 shadow-utils 的包. 对于配置文件 /etc/shadow ,则来自一个叫 ...
- 8007003Windows Update遇到未知错误
如果在检查更新时收到 Windows Update 错误 80070003,则需要删除 Windows 用于标识计算机更新的临时文件.若要删除临时文件,请停止 Windows Update 服务,删除 ...