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的通信方式是半 ...
随机推荐
- int和long long有符号整形 负数比正数多一个
int的负数比正数多一个,则有一个负数在int范围内没有对应的正数 最大正整数用十六进制,很容易表示:0x7f ff ff ff int num = 0x7fffffff; num = -num; p ...
- ofbiz进击 。 ofbiz 退货流程(包含获取可退货项流程分析 以及 取消退货项的过程分析)
根据订单获取可退货项流程分析 退货的时候,调用 services_return.xml 中的获取可进行退货的退货项 getReturnableItems ,该服务调用了Java类 org.ofbi ...
- 使用Eclipse构建Maven项目 (转)
Maven这个个项目管理和构建自动化工具,越来越多的开发人员使用它来管理项目中的jar包.本文仅对Eclipse中如何安装.配置和使用Maven进行了介绍.完全step by step. 如果觉得本文 ...
- run()和star()区别
run()和star()区别 run()-->只是thread类的一个普通方法调用 star()-->用来启动线程,实现多线程运行
- demo06
city_data.xml <?xml version="1.0" encoding="utf-8"?> <resources> < ...
- oracle的例程
oracle只有在具备sysoper和sysdba权限下才能启动和关闭例程 关闭例程: --正常关闭(等待当前连接的所有用户与数据库断开) shutdown normal; --立即关闭(回退活动的事 ...
- PAT乙级 1005. 继续(3n+1)猜想 (25)
1005. 继续(3n+1)猜想 (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz ...
- 【fedora】强制解除yum锁定
运行yum makecache时出现yum update时候出现Another app is currently holding the yum lock解决方法yum被锁定了. 可以通过执行 rm ...
- 关于MyEcplise中常见的问题和解决方案
1.问题:严重 The web application created a ThreadLocal with key of type and a value of type but fail ...
- 赤手空拳编写C#代码
有时候服务器上并没有安装任何IDE或典型的代码编辑器,只能完全手写C#代码. 不妨假设一台全新的PC,较新版本的Windows自带了.net框架,无需开发工具即可编程了. 除了以往的Bat批处理.VB ...